Skip to content

Instantly share code, notes, and snippets.

@boyofgreen
Created April 4, 2012 03:01
Show Gist options
  • Save boyofgreen/2297441 to your computer and use it in GitHub Desktop.
Save boyofgreen/2297441 to your computer and use it in GitHub Desktop.
HTML5 Hacks 2.7
input[type=number]{border: 2px solid green}
input:invalid {border: 2px solid red}
<form name="myForm">
Pick a number, any number between 1 and 5: <input type="number" name="quantity" min="1" max="5" /> <br />
<input type="submit" name="mySubmit" />
</form>
document.myForm.quantity.addEventListener('input', function(e){this.checkValidity()}, false);
document.myForm.quantity.addEventListener('invalid', function(e){
alert('Your Number needs to be between 1 and five, you choose '+this.value+'.')
}, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment