When I use pattern in input like this:
<input type="text" value="" pattern="(\d|(\d,\d{0,2}))">
I receive popup warning with text. How can I easily change this text?
When I use pattern in input like this:
<input type="text" value="" pattern="(\d|(\d,\d{0,2}))">
I receive popup warning with text. How can I easily change this text?
<input type="text" value="" pattern="(\d|(\d,\d{0,2}))" title="YOUR_WARNING_TEXT" >
<input type="text" value="" pattern="(\d|(\d,\d{0,2}))" oninvalid="this.setCustomValidity('ERROR_TEXT')" oninput="this.setCustomValidity('')"/>
Try this code, corrected to clear after input...
The text shown can be defined in the title
attribute of the input
tag.
The title
is appended to the pattern warning. Just keep in mind the warnings are translated into the browser language, which can make an english string look odd.
This is the only way I found to completely replace the warning:
<input type="text" required pattern="PATTERN" oninvalid="invalid" oninput="invalid">
/**
* Shows a custom validity message
* @param e - event
*/
function invalid(e) {
if (!/PATTERN/.test(e.target.value)) { // somehow validity.valid returns a wrong value
e.target.setCustomValidity('INVALID')
} else {
e.target.setCustomValidity('')
}
}
Once the form is validated, the warning keeps popping up until the value matches the pattern. If the input
event is just setting setCustomValidity('')
as suggested in most other answers, the default warning returns.