How to validate a letter and whitespace only input via JavaScript regular expression

后端 未结 6 1345
甜味超标
甜味超标 2021-01-04 10:55

I have an input type=\"text\" for names in my HTML code. I need to make sure that it is a string with letters from \'a\' to \'z\' and \'A\' to \'Z\' only, along

6条回答
  •  [愿得一人]
    2021-01-04 11:56

    You can use javascript test() method to validate name field. The test() method tests for a match in a string.

    /^[A-Za-z\s]+$/.test(x) //returns true if matched, vaidates for a-z and A-Z and white space
    

    or

    /^[A-Za-z ]+$/.test(x)
    

提交回复
热议问题