When filling form field only numbers should be taken as input and displayed on the form field.When other characters like 'a' are filled,they are not displayed on the form field .Only previously given numbers are seen.It should be done using core javascript.
Asked
Active
Viewed 55 times
-2
-
how about `` ? – RomanPerekhrest Apr 19 '16 at 07:23
-
we have condition that input type should be text:core javascript – Sajal Apr 19 '16 at 07:26
-
show your efforts, that is 'event handler' – RomanPerekhrest Apr 19 '16 at 07:28
-
Thank you...problem solved.I did it using onkeypress event,charCode,keyCode.... – Sajal Apr 19 '16 at 09:46
2 Answers
0
http://www.w3schools.com/html/tryit.asp?filename=tryhtml_input_number
<input type="number">
That should be what you need.
Edit: After seeing your comment: This is not your solution, because you want a javascript solution. This should have been in your question, because it is essential to answering the question.

Tim
- 96
- 4
0
Take a look at this
How To Only Allow Alpha Numeric Chars With JavaScript
and try to replace the regexp with if(!/^[0-9]+$/.test(name))
.

Community
- 1
- 1

aldebaran-ms
- 666
- 6
- 18
-
You're welcome...but what about a +1 or sign it as the answer? :) – aldebaran-ms Apr 19 '16 at 10:01
-
Another thing, remember to check the values also server side because a javascript check could be easily by-passed by a malevolent user. – aldebaran-ms Apr 19 '16 at 10:06