Skip to content

Instantly share code, notes, and snippets.

@khoand0000
Last active October 28, 2015 10:55
Show Gist options
  • Save khoand0000/9a2ccb4feda24cff3d08 to your computer and use it in GitHub Desktop.
Save khoand0000/9a2ccb4feda24cff3d08 to your computer and use it in GitHub Desktop.
validate inputs (number, email) by using pattern & show custom error messages. suggestion: using http://parsleyjs.org/
<!-- number is positive -->
<input type="number" pattern="[0-9]+" />
<!-- email -->
<input type="email" pattern="([a-z0-9_]+|[a-z0-9_]+\.[a-z0-9_]+)*@([a-z0-9]|[a-z0-9]+\.[a-z0-9]+)+\.([a-z]{2,4})" />
<!-- Vietnamese phone -->
<input type="tel" pattern="0[0-9]{9,10}" />
<!--
show custom error messages
suggestion: http://parsleyjs.org/
complex solution: http://stackoverflow.com/questions/13798313/set-custom-html5-required-field-validation-message
simple solution: http://stackoverflow.com/questions/10361460/how-can-i-change-or-remove-html5-form-validation-default-error-messages
-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment