Registration Form Validation Using Javascript

There are two methods for validating a form

  1. Using a keyword “validate” inside the input tag (<input type=”text” name=”userid” placeholder= “User-Id” size=”20″ required />).

This Will present output as:-

This will present error output as “! Please fill out the field

Complete code for the above form is shared below :-

Presented output for the above operation :-

2. Using function call we need to define a function that will validate the field data and return corresponding errors.

We need to write the html code for input field in the form

<form><label><b> User-Id</b>  </label>   <input type=”text” name=”userid” placeholder= “User-Id” size=”20″ id=”userId” /> <p id=”error1″></p></form>

First we need to call the function on submit of form as (<form name=”myForm”  onsubmit=”return validateForm()” methord=”post”>) Then we need to define the function

This would produce output as

Complete code for the above function is shared below :-

Conclusion:- Validating a form in javascript is easy and is done with the function call and displays an error with respect to the type of input in the field.

abhishek k
Tagged : / / / / / /

One thought on “Registration Form Validation Using Javascript

Leave a Reply