Is there a quick way to set an HTML text input () to only allow numeric keystrokes (plus \'.\')?
I saw some great answers however I like them as small and as simple as possible, so maybe someone will benefit from it. I would use javascript Number()
and isNaN
functionality like this:
if(isNaN(Number(str))) {
// ... Exception it is NOT a number
} else {
// ... Do something you have a number
}
Hope this helps.