Tuesday, 25 August 2015

User Name Validation (Contain letters only) using Java Script

HTML File
  
   
  <div class="lbl">First Name:</div>
  <div class="ctrl" style="float: left;">
       <input type="text" name="fname">
       <span id ="err_fname"></span>
  </div>
  
Java Script File
  
   
function fname_validation(fid)
{
    var letters = /^[A-Za-z]+$/;
    if (fid.value.match(letters))
    {
        document.getElementById("err_fname").innerHTML = "";
        return true;
    }   
    else
    {
        document.getElementById("err_fname").innerHTML = "Enter char only";
        fid.focus();
        return false;
    }
    
}
  

No comments:

Post a Comment