javascript validation registration form

javascript validation registration form

Today, We want to share with you javascript validation registration form.In this post we will show you Registration form validation using javascript with example, hear for Registration form with javascript validation we will give you demo and example for implement.
In this post, we will learn about Form validation with javascript with an example.

JavaScript mostly used to make web and interactive webside.

Simple Used in JavaScript

Welcome to JavaScript Form Validation using a Sample Registration Form

  
    document.write("JavaScript Form Validation using a Sample Registration Form by JavaScript");  
    

There are Two type of validation.
1) Client Side Validation using Js.
2) Server side Validation using PHP,CI,.NET,etc..

Read Also:  Javascript Forms Required Fields validation Example

Simple HTML Form Validation using JavaScript.If a Form input or field name is empty ,and this function generate alert and show appropriate Message display.It’s generate message will form submit.There are lots of keywords using javascript Validation.
It’s used create a form submission and before the form is submitted, and Confirm or check verify the credentials.It’s Client mean Browser side validation using JavaScript.

List Of JavaScript Validation Attributes.

1 required
2 type
3 max
4 min
5 pattern
6 disabled
7 regexp

IN this JavaScript using validateForm, We are going to validate name,age and city.and the name,age and city can’t be empty.

Using the Form Validation script

HTML page : validation.html

Read Also:  Validate Email and Password Fields on Form Submit Event


	<title>Simple JavaScript Form Validation</title>



<div id="errors">

<strong>The following field(s) must be filled out:</strong>

<ul id="errorList">
  </ul>
</div>

Example Form Validation using JavaScript.

<form method="POST">
  <label for="A">Name</label>
    
  <label for="B">Age</label>
    
  

  <label for="C">City</label>
    
   

   
</form>


Include css

It’s id of Errors and Dsiplay this errors and color using css.

#errors {
  display:none;
  color:red;
}

Include Script

Call validateForm function and check field Empty or not Empty.if This field empty so return false.and it’s field not empty so return true and submited.

function validateForm()
{
  var errorMsg = ''
  var errorDisplay = $("#errors");
  var errorList = $("#errorList"); 
  errorList.find("li").remove();
	var name = $("#A").val();
  var age = $("#B").val();
  var city = $("#C").val();
  if (!name) {
  	errorMsg += '

<li>Name</li>


';
  }
  
  if (!age) {
  	errorMsg += '

<li>Age</li>


';
  }
  
  if (!city) {
  	errorMsg += '

<li>City</li>


';
  }
	if (errorMsg.length > 0) {
  	errorList.append(errorMsg);
  	errorDisplay.css("display","block");
    return false;
  }
  else
  {
  	return true;
  }
}