Javascript - validation, numbers only

前端 未结 14 1717
感动是毒
感动是毒 2020-12-08 09:52

I\'m trying to get my login form to only validate if only numbers were inputted. I can it to work if the input is only digits, but when i type any characters after a number,

14条回答
  •  我在风中等你
    2020-12-08 10:24

    function validateNumber(e) {
                const pattern = /^[0-9]$/;
    
                return pattern.test(e.key )
            }
     
     

    This approach doesn't lock numlock numbers, arrows, home, end buttons and etc

提交回复
热议问题