-2

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.

Sajal
  • 3
  • 5

2 Answers2

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