Here are the javascript functions to check various field validation. For example with these javascript functions we can check whether registration forms field fulfills specific validation criteria or not.

Validation for String Length

This javascript function will check whether  particual field satisfies the length criteria.

inputtxt—It is FieldId of field to check for validation.

minlength-Minimum length of text field

maxlength-Maximum length of text field

function  checkFieldLength(inputtxt, minlength, maxlength)     
{            
var txtElmVal=document.getElementById(inputtxt).value; //Returns First element by Id       
if(txtelmVal.length >= minlength && ttxtelmVal.length <= maxlength)            
{                   
return true;                
}         
else            
{                   
alert("Field length should between " +minlength+ " and " +maxlength+ " characters");                     
return false;               
}               
} 

Validation for Letters only

This javascript fuction will check whether field contains only letters or not.

inputtxt—It is FieldId of field to check for validation.

function  checkisAllletters (inputtxt)      
{
       var txtelmVal=document.getElementById(inputtxt).value;
       var reg=/^[A-Za-z]+$/;
       if (!reg.test(txtelmVal))
      {
             alert("Field should contain only letters.");
             return false;
         }
         else
             return true;
} 

 Validation for Letters and Numbers only

 inputtxt—It is FieldId of field to check for validation. 

function  checkisAlphanum (inputtxt)
{
         var txtelmVal=document.getElementById(inputtxt).value;
         var reg=  /^[0-9a-zA-Z]+$/;
         if (!reg.test(txtelmVal))
         {
            alert("Field should contain only letters and numbers.");
            return false;
         }
         else
           return true;
}  

 Validation for Email

  txtemail-—It is FieldId of Emailfield to check for validation.

function checkvalidEmail(txtemail)
{
          var txtelmVal=document.getElementById(inputtxt).value;
          var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
          if (!reg.test(txtelmVal))
          {
             alert("Please enter valid EmailId");
             return false;
           }
           else
              return true;
}