hi,
i need to restrict my input field so it can only be filled by number, i manage to restricted the input field Example
but it didn't work like i want, all i want is to prevent user to type/input alphabet into the field.
ohh btw, if it's possible i want to use only javascript not jquery
Hi,
HTML5 can do this: http://www.w3schools.com/html/html5_form_input_types.asp
And then validating the field after a submit and respond accordingly for browsers that don't support this (yet).
Just like you would do to check if a valid email address was entered.
HTH
yeah i tried that before but i doesn't compatible with some browser, and about validate the field when submit i already do that but i think it's more easier for user if we already restricted the input field just for number only.
hi,
i need to restrict my input field so it can only be filled by number, i manage to restricted the input field Example
but it didn't work like i want, all i want is to prevent user to type/input alphabet into the field.
ohh btw, if it's possible i want to use only javascript not jquery
Hi, HTML5 can do this: http://www.w3schools.com/html/html5_form_input_types.asp And then validating the field after a submit and respond accordingly for browsers that don't support this (yet). Just like you would do to check if a valid email address was entered. HTH
yeah i tried that before but i doesn't compatible with some browser, and about validate the field when submit i already do that
but i think it's more easier for user if we already restricted the input field just for number only.
Ok. Then jQuery: $('.numbers').keypress(function(key) { if(key.charCode < 48 || key.charCode > 57) return false; });
Formatting on CSS-tricks is a bit tricky sorry: HTML:
jQuery: $('.numbers').keypress(function(key) { if(key.charCode < 48 || key.charCode > 57) return false; });
Sorry again. Look at this: http://codepen.io/begetolo/pen/jvldz
Or without jQuery: http://codepen.io/begetolo/pen/pGntl
(found this on http://stackoverflow.com/questions/2808184/restricting-input-to-textbox-allowing-only-numbers-and-decimal-point)
@Bert nice,that's what i was looking for
thank you very much.
You're welcome. Glad I could help.