Tuesday, 25 August 2015

Pin Code Validation (Contain 6 digit only) using Java Script

HTML File
  
   
  <div class="lbl">Pincode : </div>
  <div class="ctrl">
       <input type="number" name="pin">
       <span id ="err_pin"></span>
  </div>
  
Java Script File
  
   
function pin_validation(pin)
{                                                          
    var reg = /^([0-9]{6})$/;
        if (pin.value.match(reg))
        {
            document.getElementById("err_pin").innerHTML = "";
            return true;
        }
        else
        {
            var msg = "please enter valid Pincode...";
            document.getElementById("err_pin").innerHTML = msg;
            pin.focus();
            return false;
        }
}
  

1 comment: