Hello Reader!
If you have been working with HTML 5 validation then on incorrect email address web broser will show the default error message "please enter a valid email address".
Now you can make it custom and write your own message. Lets see the code below:-
Then HTML form is as same:-
<form id="myform">
<input id="email" oninvalid="InvalidMsg(this);" name="email" oninput="InvalidMsg(this);" type="email" required="required" />
<input type="submit" />
</form>
Now in the JS code :-
function InvalidMsg(textbox) {
if (textbox.value == '') {
textbox.setCustomValidity('Required email address');
}
else if(textbox.validity.typeMismatch){
textbox.setCustomValidity('please enter a valid email address'); //write your custom code here
}
else {
textbox.setCustomValidity('');
}
return true;
}
As you can now put your own custom message on 'text.setCustomValidity'
Source By :- jsfiddle.net
0 Comment(s)