
Change default message of a field type=’email’ required
If you are filling in a form, with an input type email, and you need to change the default HTML5 message:
you will need a bit of javascript, as follows:
HTML:
1 |
<input name="field_name" id="field_id" type="email" oninput="InvalidMsg(this);" oninvalid="InvalidMsg(this)"required="required"> |
JS:
1 2 3 4 5 6 7 8 9 10 11 12 |
function InvalidMsg(textbox){ if (textbox.value == '') { textbox.setCustomValidity('Please, fill in an email.'); } else if(textbox.validity.typeMismatch){ textbox.setCustomValidity('Please, fill in a valid email.'); } else { textbox.setCustomValidity(''); } return true; } |