1. function getByteLen(val) {
    2. let len = 0
    3. for (let i = 0; i < val.length; i++) {
    4. let a = val.charAt(i)
    5. if (a.match(/[^\x00-\xff]/gi) != null) {
    6. len += 2
    7. } else {
    8. len += 1
    9. }
    10. }
    11. return len
    12. }