javascript - Checking input values for special symbols - Stack Overflow

I am having two text fields in my form. The data to be entered in the field are Name and City respectiv

I am having two text fields in my form. The data to be entered in the field are Name and City respectively. I want to check that the user has not entered any special symbols like !,@,#........ i.e, the only thing user should enter must be belonging to a-z,A-Z, though the user can enter Underscore(_), but no numbers, no special symbols.

I want to check this using JavaScript, how can this be achieved.

Thanks in advance.

I am having two text fields in my form. The data to be entered in the field are Name and City respectively. I want to check that the user has not entered any special symbols like !,@,#........ i.e, the only thing user should enter must be belonging to a-z,A-Z, though the user can enter Underscore(_), but no numbers, no special symbols.

I want to check this using JavaScript, how can this be achieved.

Thanks in advance.

Share Improve this question asked Oct 4, 2010 at 8:06 LoganLogan 2,5155 gold badges38 silver badges59 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

A classic problem that's usually solved with the help of regular expressions.

var myString = "London";
if (myString.match(/^[a-zA-Z_]+$/)) {
    // Success
}

If you want to allow spaces, like for New York, change the pattern to /^[a-zA-Z_\s]+$/.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744936379a4602050.html

相关推荐

  • javascript - Checking input values for special symbols - Stack Overflow

    I am having two text fields in my form. The data to be entered in the field are Name and City respectiv

    1天前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信