i have some script java script which is working but i want to do it some thing else

<script type="text/JavaScript">

 
 
 function validate_required(field,alerttxt)
{
with (field)
  {
  if (value==null||value=="")
    {
    alert(alerttxt);return false;
    }
  else
    {
    return true;
    }
  }
}

function validate_form(thisform)
{
with (thisform)
  {
  if (validate_required(email,"Email must be filled out!")==false)
  {email.focus();return false;}
  }
}




function validate_email(field,alerttxt)
{
with (field)
  {
  apos=value.indexOf("@");
  dotpos=value.lastIndexOf(".");
  if (apos<1||dotpos-apos<2)
    {alert(alerttxt);return false;}
  else {return true;}
  }
}

function validate_form(thisform)
{
with (thisform)
  {
  if (validate_email(email,"Not a valid e-mail address!")==false)
    {email.focus();return false;}
  }
}
 
 
 

function valid(f) {
if (!/^\d*$/.test(f.value)) {
alert("Only integer numbers allowed!");
f.value = f.value.replace(/[^\d]/g,"");
}
}


 
 
 </script>

This script is working for email validation also if email box is empty it says to fill it i want that for all if some one left any box in form it says fill that.

i have tried many ways but failed that's why posting here.

and the last function is for contactno INPUT field so one can only put number in the field.

HTML CODE

<div id="forminfo"><form name="theform" action="<?php echo $_SERVER['PHP_SELF']; ?>" onsubmit="return validate_form(this)" method="POST">
    First Name:
                 <INPUT type="text" name=fname style="HEIGHT: 19px; WIDTH: 174px" size="20" align="center">
    <br>
    <br>
    
    Last Name:
                <INPUT type="text" name=lastname style="HEIGHT: 19px; WIDTH: 174px" size="20" align="center">
    <br>
    <br>
    
    Email Address:       <INPUT type="text" name=email style="HEIGHT: 19px; WIDTH: 174px" size="20" align="center">
    <br>
    <br>
    
    Address:
                      <INPUT type="text" name=address style="HEIGHT: 19px; WIDTH: 174px" size="20" align="center">
    <br>
    <br>
    
    City:
                                  <INPUT type="text" name=city style="HEIGHT: 19px; WIDTH: 174px" size="20" align="center">
    <br>
    <br>
    
    Province:
                     <INPUT type="text" name=province style="HEIGHT: 19px; WIDTH: 174px" size="20" align="center">
    <br>
    <br>
    
    Contact No:
                <INPUT type="text" name=contactno maxlength="11" onkeyup="valid(this)"  style="HEIGHT: 19px; WIDTH: 174px" size="20" align="center">
    <br>
    <br>
    <br>
                                                                                          <input type="submit" name="submit" value="submit" />
    
    </form>

You can sanitize the field's using regular expression, which allow's you to specify pattern's that will validate's against field entries...

This article has been dead for over six months. Start a new discussion instead.