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

前端 未结 5 1315
说谎
说谎 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:38

    var chkName = /\s/;
    
    function check(name) {
    
        document.write("
    " + name + " is "); if (!chkName.test(name)) { document.write("okay"); } else { document.write("invalid"); } } check("namevaluegoeshere"); check("name value goes here");

    This way you just check if there's any white space in the name.

    demo @ http://jsfiddle.net/roberkules/U3q5W/

提交回复
热议问题