Check if input is number or letter javascript

前端 未结 12 1323
遇见更好的自我
遇见更好的自我 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:29

    you can use isNaN(). it returns true when data is not number.

    var data = 'hello there';
    if(isNaN(data)){
      alert("it is not number");
    }else {
      alert("its a valid number");
    }
    

提交回复
热议问题