8

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

What's the equivalent for WebKit?

Matt
  • 74,352
  • 26
  • 153
  • 180
Humphrey Bogart
  • 7,423
  • 14
  • 52
  • 59

2 Answers2

10

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)

Jon Raasch
  • 3,703
  • 6
  • 30
  • 32
1

I'm almost certain there isn't, and it doesn't look like it's going to happen: http://www.w3.org/Bugs/Public/show_bug.cgi?id=10923.

You might want to check out setCustomValidity(). It seems to work fine in Chrome for me: http://olav.dk/wf2/demo/validation.asp.

Source: http://www.whatwg.org/specs/web-apps/current-work/multipage/association-of-controls-and-forms.html#dom-cva-setcustomvalidity

Nick
  • 6,967
  • 2
  • 34
  • 56