Machi Machi - 1 year ago 108
HTML Question

How to validate an interval entered to a text input field

is there please a way to define a number interval (let's say between 1900 and 2016) that can only be entered to a text input field? We have to use input type="text" because number field can't be used for a jQuery keyboard. We need to enter values both by a virtual and real keyboard (see and check the number interval each time user tries to submit the form.

Thank you!

Answer Source

This is the far most I can get to without doing any dirty work.


if ((number < 1900) || (number > 2016))

This use the combination of having a pattern to check (4 digits only when submitting) and javascript (I used jQUery) to check for number range. The combination will allow you not messing around with a pattern in low level (limit the exact digit to be inputted).

However, if you still want to limit the user input, not checking afterward, you still can with oninput and manually limit out the next possible options.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download