Last Updated : Jan 1, 2023
And this article is minor different from that because with help of these codes we are also able to alert messages when an error occurs.
In first, we can use alert to show error messages and another one is with the help of inner html in which we display a line that an error has occurred.
Both are convenient ways and depend upon how you use them. Now, let us see how to apply validation with message with help of alerts.
In next session we will show you an example of error messages using inner html.
- For this first of all we here create a basic structure of html. For this we use html, head, title and body with script tag. We hope you know about the basic structure of html and which html tag is used for which concept.
- Here, as we see that we create a basic registration form on which we are going to apply validations with error messages. Here, we use our three fields that are email, username and password with a button to submit that form.
- Here, as you see we apply our basic validations in which if any thing remains empty at the time of submission of form and password is less than 8 characters than it will focus that thing and shows an alert message related to error.