<!DOCTYPE html>
<html>
<body>
<h3> Send review request to test@something.com:</h3>
<script type="text/javascript">
function FormValidator(theForm)
{
// check to see if the field is blank
if (theForm.sname.value == "")
{
alert("Sandbox name should not be blank");
theForm.sname.focus();
return (false);
}
// require at least 3 characters be entered
if (theForm.sname.value.length < 3)
{
alert("Please enter at least 3 characters in the \"Sandbox Name\" field.");
theForm.sname.focus();
return (false);
}
// allow ONLY Capital Alphabeticals
var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_";
var checkStr = theForm.sname.value;
var allValid = true;
for (i = 0; i < checkStr.length; i++)
{
ch = checkStr.charAt(i);
for (j = 0; j < checkOK.length; j++)
if (ch == checkOK.charAt(j))
break;
if (j == checkOK.length)
{
allValid = false;
break;
}
}
if (!allValid)
{
alert("Please enter only Capital Alphabetics \"Sandbox Name\" field.");
theForm.sname.focus();
return (false);
}
if (theForm.plead.value == "")
{
alert("Project Lead login field should not be blank");
theForm.plead.focus();
return (false);
}
var checkOk1= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
var checkStr1 = theForm.plead.value;
var allValid1= true;
for (i = 0; i < checkStr1.length; i++)
{
ch = checkStr1.charAt(i);
for (j = 0; j < checkOK1.length; j++)
if (ch == checkOK1.charAt(j))
break;
if (j == checkOK1.length)
{
allValid1 = false;
break;
}
}
if (!allValid1)
{
alert("Please enter only Alphabets \"Project Lead Login\" field.");
theForm.sname.focus();
return (false);
}
if (theForm.talias.value == "")
{
alert("Team alias should not be blank");
theForm.talias.focus();
return (false);
}
var checkOk2= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-";
var checkStr2 = theForm.talias.value;
var allValid2= true;
for (i = 0; i < checkStr2.length; i++)
{
ch = checkStr2.charAt(i);
for (j = 0; j < checkOK2.length; j++)
if (ch == checkOK2.charAt(j))
break;
if (j == checkOK2.length)
{
allValid2 = false;
break;
}
}
if (!allValid2)
{
alert("Please enter only Alphabets \"Team Alias\" field.");
theForm.talias.focus();
return (false);
}
return(true);
}
</script>
<form action="MailTo:ynaveen9@something.com" method="post" name="theForm" onsubmit="return FormValidator(this);" >
<p>
Sandbox Name:<br />
<input type="text" name="sname" /><br />
Project Lead<br />
<input type="text" name="plead" /><br />
TeamAlias<br />
<input type="text" name="talias" /><br />
<input type="Submit" value="Sendmail" name="btn">
<input type="reset" value="Reset"> </p>
</form>
</body>
</html>
I have one script which irritating me for some days. This is perfectly validating 1st field. For the 2nd field it's not validating for alphabets and there onwards it's not checking any Validation. I have 10 fields in my original script, all text fields only). This is really frustrrating me. Could u pls help?
Am using same validation script for all the fields. Not sure why it's not working..