Monday, 15 February 2016

Text box validation on Key press

Dear All,
It is always mandatory to validate textbox in the keypress event. Please see the code

file name : validatetext.php


<html>
<head>
<!--
Coded by Prof. Sajeev Jaladharan
Date : 27.11.2015
email: sajeevjal@gmail.com
-->
<title>SNIT MCA Online Registration</title>

<script>
function checkname()
{

   
    /*if(!isNaN(name))
    {
        alert('Enter characters only');
        document.reg.Name.value='';
        document.reg.Name.focus();
    }
    */
        name=document.reg.Name.value;
   
    var letters = /^[A-Za-z]+$/; 
   if(name.match(letters)) 
     { 
      return true; 
     } 
   else 
     { 
     alert("No numbers or blank space please");
     document.reg.Name.value='';
        document.reg.Name.focus();
     return false; 
     } 
}



</script>
</head>
<body background="img.jpg" >
<table border=0 width=63% align="center" bgcolor="#EFFBFC">
<tr><td>

<form name="reg" class="wufoo topLabel page" method="post" action="saveadmission.php" onSubmit="return checkname()">
  <table style="border-color:#669999;border-style:dashed ;" align="center" cellpadding="2" cellspacing="2" width="85%">
    <tbody>
    <tr>
      <td>Name </td>
      <td><input id="Name" name="Name" style="width:150px" size="20" tabindex="2" type="text" onKeyUp="javascript:checkname()"></td></tr>
  
      <td colspan="2"><strong><blockquote class="style1"><span>For Communication Purpose</span></blockquote></strong></td></tr>
    <tr>
    
 
      <td colspan="2"><div align="center">
        <input name="Save" id="Save" value="Save Data" type="submit" tabindex="21">
        <label>
        <input name="Reset" value="Clear Form" type="reset">
        </label>
      </div></td></tr>
  </tbody></table>
  <div class="info" align="center">
</div>
</form>
</td></tr></table>
</body>
</html>

No comments:

Post a Comment