Skip to content

Instantly share code, notes, and snippets.

@waila7
Forked from scrubmx/HTML5Validation.html
Created December 19, 2017 11:59
Show Gist options
  • Select an option

  • Save waila7/e1f463e5125afab6dcd08828b3930f9a to your computer and use it in GitHub Desktop.

Select an option

Save waila7/e1f463e5125afab6dcd08828b3930f9a to your computer and use it in GitHub Desktop.
Change the language of error message for html5 required fields.
/*
|-----------------------------------------------------------------------
| With HTML
|-----------------------------------------------------------------------
*/
<input
type="number"
id="userProvidedHeight"
min="211"
max="400"
placeholder="211 — 400"
oninvalid="setCustomValidity('Ingresa un numero entre 211 y 400.')"
oninput="setCustomValidity('')"
required
/>
/*
|-----------------------------------------------------------------------
| With jQuery
|-----------------------------------------------------------------------
*/
<script>
$('input[type="email"]')
.on('invalid', function(){
return this.setCustomValidity('Ingresa una dirección de correo válida.');
})
.on('input', function(){
return this.setCustomValidity('');
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment