0
   

Help me out...

 
 
Reply Mon 14 Sep, 2009 10:23 am
i have writen the following simple program to perform validations on a html page using javascript but it is not validating,kindly help me to find out the error


/*html file*/
<html>
<head>
<title>valid check</title>
<script type='text/javascript' src='valchk.js'></script>
<script language="javascript">
function val()
{
if(!valname(document.mine.name,3,"not a proper name"))
return false;
if(!valmb(document.mine.mb,10,"not a valid phone no"))
return false;
if(!valemail(document.mine.email,6,"not a proper email id"))
return false;
return true;
}
</script>
</head>
<body>
<form name="mine">
name: <input type="text" name="name" size=6 > <br>
mobile no : <input type="text" name="mb" size=15 > <br>
email : <input type="text" name="email" size=6 > <br>
<Input type="Submit" onClick="return val()"><br>
</form>
</body>
</html>



/*javascript file*/
function valname(field,rlength,msg)
{
var par=true;
var a=field.value;
var tlength=a.length;
if(tlength<rlength)
{
par=false;
}
if(tlength>=rlength)
{
for(var i=0;i<tlength;i++)
{
var k= a.substring(i,i+1);
if(!((k>="a" && k<="z") || (k>="A" || k<="Z") ||(k==" ")))
{
par=false;
}
}
}
if(par==false)
{
alert(msg);
}
return true;
}


function valmb(field,rlength,msg)
{
var par=true;
var a=field.value;
var length=a.length;
if(length==rlength)
{
par=false;
}
if(length>=rlength)
{
for(var i=0;i<length;i++)
{
var k=a.substring(i.i+1);
if(!(k>="0 || k<="9"))
{
par=false;
}
}
}
if(par==false)
{ alert(msg);
}
return true;
}


function valemail(thefield,therlength,themessage)
{
var theinput=thefield.value;
var thelength=theinput.length;
var goodzip=true;
if(thelength<therlength)
{
goodzip=false;
}
if(theinput.indexOf("@")==-1)
{
goodzip=false;
}
if(goodzip==false)
{
alert(themessage);
}
return true;
}

  • Topic Stats
  • Top Replies
  • Link to this Topic
Type: Question • Score: 0 • Views: 1,808 • Replies: 0
No top replies

 
 

Related Topics

YouTube Is Doomed - Discussion by Shapeless
So I just joined Facebook.... - Discussion by DrewDad
Internet disinformation overload - Discussion by rosborne979
Participatory Democracy Online - Discussion by wandeljw
OpenDNS and net neutrality - Question by Butrflynet
Internet Explorer 8? - Question by Pitter
 
  1. Forums
  2. » Help me out...
Copyright © 2024 MadLab, LLC :: Terms of Service :: Privacy Policy :: Page generated in 0.05 seconds on 12/21/2024 at 07:27:09