Nowadays, all modern browsers support most of the features of HTML5. The functionality of the features is the same in all browsers but there are some differences; one of which is the default error message that the browser, displays.
Some of the default error messages displayed by various browsers are shown in the following screenshot:
However, we can change the default error message of the browser with the help of setCustomvalidity
. Let us understand this with an example.
The following code changes the default error message of a browser to a custom message:
<script> function check() { varhtmlObject=document.getElementById("input"); if (!htmlObject.checkValidity()) { htmlObject.setCustomValidity('This field is mandatory'); } } </script> <body> <form id="myForm"> <input id="input" type="text" required /> <input type="submit" onclick="check(this)"> </form> </body>