By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,826 Members | 2,384 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,826 IT Pros & Developers. It's quick & easy.

isNaN function on a textbox in a form

P: 2
I am using HTML and JS to make a form, but one of the text boxes needs to validate that it will only accept digits as it is for a number, but I can't figure out how to do this with the isNaN function.
PS it also has to be exactly four digits long

Any help would be appreciated thanks
Sep 24 '14 #1
Share this Question
Share on Google+
3 Replies


Dormilich
Expert Mod 5K+
P: 8,639
HTML5 solution
Expand|Select|Wrap|Line Numbers
  1. <input type="number">
if number boxes are not supported:
Expand|Select|Wrap|Line Numbers
  1. // 'input' be the text box DOM element
  2. if (isNaN(input.value)) {
  3.     // validation failed
  4. }
Sep 24 '14 #2

P: 2
ok, but now when i click submit with only numbers in the textbox, it still shows the dialog saying you must enter digits only
Sep 24 '14 #3

Dormilich
Expert Mod 5K+
P: 8,639
show your code.
Sep 24 '14 #4

Post your reply

Sign in to post your reply or Sign up for a free account.