Friday, March 15, 2013

HTML / ASP net controller accepts numeric values

HTML/ASP net controller so that it only accepts numeric values



1)   If your using HTML 5 you can use “type” option to limit accepting input range   ex: <input type="number">

2)   Also can use regular expression  using  “pattern” option to limit integer values   ex: <input type="text" pattern="\d*" />

3)  But I feel the best option is use the JavaScript for this
<input type="textAcceptNumbers"  name="txtAceptNumbers"  onkeypress="if (event.keyCode < 45 || event.keyCode > 57)
event.returnValue = false;"></input>

No comments:

Post a Comment