Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

需求实现:仅支持中英文和数字,且字数不超过8个汉字或16个字母 #14

Open
54leibo opened this issue Mar 24, 2020 · 0 comments

Comments

@54leibo
Copy link
Owner

54leibo commented Mar 24, 2020

/**
  * @method processStr
  * @params {String} val
  * @return {String} val
*/
const processStr = val => {
      val = val.replace(/[^a-z0-9\u4e00-\u9fa5]/ig, '')
      const getLen = () => val.length + val.replace(/[^\u4e00-\u9fa5]/ig, '').length
      let mixLen = getLen()

      while (mixLen > 16) {
        val = val.slice(0, val.length - 1)
        mixLen = getLen()
      }

     return val
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant