Not allow space as a first character and allow only letters using jquery

后端 未结 3 1636
北恋
北恋 2021-01-22 09:44

Im using jquery for the name validation I have tried a code which is given below

$(\"#contactname\").keypress(function(e) {
    if(e.which < 97 /* a */ || e.w         


        
3条回答
  •  囚心锁ツ
    2021-01-22 10:33

    Can you use the HTML5 attribute pattern? See the MDN article on it for more information.

    Using a regex of ^[a-zA-Z][\sa-zA-Z]* seems to cover your requirements.

    So something like:

    Username:

提交回复
热议问题