Check if input is number or letter javascript

前端 未结 12 1318
遇见更好的自我
遇见更好的自我 2020-11-29 01:03

I\'m using forms in HTML and javascript. I would like an alert to pop up only if the user inputs a LETTER and clicks submit.

So I have

12条回答
  •  半阙折子戏
    2020-11-29 01:26

    The best and modern way is typeof (variable) if you care about real number not number from string. For example:

    var a = 1;
    var b = '1';
    
    typeof a: // Output: "number"
    typeof b: // Output: "string
    

提交回复
热议问题