How can I change or remove HTML5 form validation default error messages?

This is the JavaScript solution:

 <input type="text"
    pattern="[a-zA-Z]+"
    oninvalid="setCustomValidity('Please enter Alphabets.')"
    onchange="try{setCustomValidity('')}catch(e){}" />

The “onchange” event needs when you set an invalid input data, then correct the input and send the form again.
I’ve tested it on Firefox, Chrome and Safari.

But for Modern Browsers:

Modern browsers didn’t need any JavaScript for validation.
Just do it like this:

<input type="text"
    pattern="[a-zA-Z]+"
    title="Please enter Alphabets."
    required="" />

Leave a Comment