Check if input is number or letter javascript

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

    Thanks, I used @str8up7od answer to create a function today which also checks if the input is empty:

        function is_number(input) {
            if(input === '')
                return false;
            let regex = new RegExp(/[^0-9]/, 'g');
            return (input.match(regex) === null);
        }
    

提交回复
热议问题