I know this post is old, but it was the first that appeared when I did a search. I tried @Kim Kling RegExp, but it failed. Also, before I found this forum, I tried almost all the other options listed here. In the end, none of them worked except the one I created; It works fine, plus this is es6:
let regex = new RegExp(/[^0-9]/, 'g'); let x = document.forms["myForm"]["age"].value; if (x.match(regex)) { alert("Must be a valid number"); return }
str8up7od Sep 25 '17 at 15:32 2017-09-25 15:32
source share