Hello, Please help me with this code..I have 4 forms which link to different htmll page. I try to write one validation file that can validate for the form whenever user click on that form.How do I call Validate.js for each form? Please give me some hints.
Thanks
Validate.js
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
//test version
//read the comment i put
///////////////////////////////////////////////////////////////////////////////////////////////////////////
function do_checkEmail(x ){
//do all email checking
if(x.value.inde xOf("@")!= "-1" && x.value.indexOf (".") != "-1"){
return false;
}
else
{
return true;
}
}
function do_checkPhone(x ){
//do all phone checking phone format 999-999-9999
if(x.value.leng th !=12){
return false;
}
for(var i = 0; i < x.value.length; i++){
if ((i>-1&&i<3)||(i>3 && i<7)||(i>7&& i>12)){
if(x.value.char At(i) < "0" || x.value.charAt( i) > "9"){
return false;
}
}
//check for hyphen '-'
else if (x.value.charAt (i) != "-"){
return false;
}
}
return true;
}
//Check for empty field, last name and first name
function do_checkEmpty(x ){
if (x.value == "" || x.value == "null"){
return false;
}
else{
return true;
}
}
function checkForm(form) {
if (do_checkEmail( form.emailAdd) == false){
alert("Please enter a valid email.");
form.emailAdd.f ocus();
return false;
}
if (do_checkEmpty( form.lastname) == false){
alert("Please Enter Last Name.");
form.lastname.f ocus();
return false;
}
if (do_checkEmpty( form.firstname) == false){
alert("Please Enter First Name.");
form.firstname. focus();
return false;
}
return true;
}
//////////////////////////////////////////////////////////////////////
Thanks
Validate.js
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
//test version
//read the comment i put
///////////////////////////////////////////////////////////////////////////////////////////////////////////
function do_checkEmail(x ){
//do all email checking
if(x.value.inde xOf("@")!= "-1" && x.value.indexOf (".") != "-1"){
return false;
}
else
{
return true;
}
}
function do_checkPhone(x ){
//do all phone checking phone format 999-999-9999
if(x.value.leng th !=12){
return false;
}
for(var i = 0; i < x.value.length; i++){
if ((i>-1&&i<3)||(i>3 && i<7)||(i>7&& i>12)){
if(x.value.char At(i) < "0" || x.value.charAt( i) > "9"){
return false;
}
}
//check for hyphen '-'
else if (x.value.charAt (i) != "-"){
return false;
}
}
return true;
}
//Check for empty field, last name and first name
function do_checkEmpty(x ){
if (x.value == "" || x.value == "null"){
return false;
}
else{
return true;
}
}
function checkForm(form) {
if (do_checkEmail( form.emailAdd) == false){
alert("Please enter a valid email.");
form.emailAdd.f ocus();
return false;
}
if (do_checkEmpty( form.lastname) == false){
alert("Please Enter Last Name.");
form.lastname.f ocus();
return false;
}
if (do_checkEmpty( form.firstname) == false){
alert("Please Enter First Name.");
form.firstname. focus();
return false;
}
return true;
}
//////////////////////////////////////////////////////////////////////
Comment