Reputation: 461
How can I add validation for the HTML5 input type range?
It should not be 0. How can I add a warning message, like the default validation messages on other HTML5 input types?
Upvotes: 2
Views: 5027
Reputation: 1019
I'd add the pattern attribute:
pattern="[1-1000]"
That requires a number entered between 1 and 1000
I'd also add:
required="required"
Upvotes: 1
Reputation: 425
Example: <input type="number" size="6" name="age" min="18" max="99" value="21">
Some more examples: HTML5 Validation Types
Upvotes: 1
Reputation: 1212
You can check if the user press the key with an eventlistener via jquery and prevent the use of it
$("input").addEventListener("keypress", function (evt) {
/*your condition*/
if ( evt.which == /*your keycode*/ )
{
evt.preventDefault();
alert(); /*you error message/code*/
}
});
http://www.webonweboff.com/tips/js/event_key_codes.aspx
Upvotes: -1