How to validate both Chinese (unicode) and English name?

前端 未结 5 1318
说谎
说谎 2021-02-01 10:14

I have a multilingual website (Chinese and English).

I like to validate a text field (name field) in javascript. I have the following code so far.

var c         


        
5条回答
  •  悲哀的现实
    2021-02-01 10:46

    You might check out Javascript + Unicode regexes and do some research to find exactly which ranges of characters you want to allow:

    See What's the complete range for Chinese characters in Unicode?

    After reading those two and a little extra research you should be able to find appropriate values to complete something like: /^[-'a-z\u4e00-\u9eff]{1,20}$/i

提交回复
热议问题