Skip to content

Instantly share code, notes, and snippets.

@momolog
Created September 29, 2014 09:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save momolog/5d2c1499b4ddd168e8bd to your computer and use it in GitHub Desktop.
Save momolog/5d2c1499b4ddd168e8bd to your computer and use it in GitHub Desktop.
How to set a custom validation message for HTML5 form inputs
$ ->
if Modernizr.input.pattern
$(document).bind 'change', (e) ->
$el = $(e.target)
$el[0].setCustomValidity ''
if $el[0] in document.querySelectorAll(':invalid')
if message = $el.data('invalidmessage')
$el[0].setCustomValidity message
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment