Skip to content

Instantly share code, notes, and snippets.

@scrubmx
Last active July 6, 2024 15:40
Show Gist options
  • Save scrubmx/bafa8c606596cf3cd5c6 to your computer and use it in GitHub Desktop.
Save scrubmx/bafa8c606596cf3cd5c6 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>
@saeid-hanafi
Copy link

thanks.

@matt-cos
Copy link

Thank you!

@MominjonVue
Copy link

thanks. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment