allowing only alphabets in text box using java script

后端 未结 6 1105
醉梦人生
醉梦人生 2020-12-02 01:28

I want to allow only alphabets in textbox using JavaScript I used the code:

var nam=f.nm.value;
if(!isNaN(nam))  
    region.innerHTML=\"alphabets only\";
<         


        
6条回答
  •  天涯浪人
    2020-12-02 02:04

    You can use HTML5 pattern attribute to do this:

    If the user enters an input that conflicts with the pattern, it will show an error dialogue automatically.

提交回复
热议问题