Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change WebKit's error message for required HTML form fields

Gecko allows you to set the error message for required HTML form fields with x-moz-errormessage.

What's the equivalent for WebKit?

like image 673
Humphrey Bogart Avatar asked Mar 18 '11 16:03

Humphrey Bogart


People also ask

How do you add a validation message in HTML?

setCustomValidity() In an input element, it is used to set the validationMessage property. It is really very easy to control a custom validation message in an HTML5 form.


1 Answers

While the setCustomValidity() example linked above works, it doesn't take into account the native HTML5 validation test, and instead supplies its own custom test. If you'd instead like to use the type match / pattern match from HTML5, then use setCustomValidity() with an oninvalid event:

<input type="text" pattern="[a-zA-Z]+"
oninvalid="setCustomValidity('Custom Message')" />

However bear in mind that this will not be localized to the user's browser language, and will also display regardless of what is invalid (e.g. it will also display if it fails the required check)

like image 57
Jon Raasch Avatar answered Sep 26 '22 17:09

Jon Raasch