function getByteLen(val) { let len = 0 for (let i = 0; i < val.length; i++) { let a = val.charAt(i) if (a.match(/[^\x00-\xff]/gi) != null) { len += 2 } else { len += 1 } } return len}