473,385 Members | 1,379 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Help with form validation with gen_validatorv2.js (desperate)

I have the following code

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript" src="..\include\gen_validatorv2.js"
type="text/javascript"></script>
</head>

<body bgcolor="#FFFFFF" text="#000000">
<form action="" method="post" name="myform" >
<table width="255" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="10" height="10"></td>
<td width="100"></td>
<td width="80"></td>
<td width="5"></td>
<td width="15"></td>
<td width="45"></td>
</tr>
<tr>
<td height="28"></td>
<td valign="top" colspan="4">email:
<input type="text" name="email">
</td>
<td></td>
</tr>
<tr>
<td height="17"></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td height="28"></td>
<td valign="top" colspan="2">email2:
<input type="text" name="email2">
</td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td height="17"></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td height="20"></td>
<td></td>
<td colspan="2" valign="top">
<input type="submit" name="Submit" value="Submit">
</td>
<td></td>
<td></td>
</tr>
<tr>
<td height="17"></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
<SCRIPT language="JavaScript">
var frmvalidator = new Validator("myform");
frmvalidator.setAddnlValidationFunction("DoCustomV alidation");
frmvalidator.addValidation("email","req");
frmvalidator.addValidation("email","email");
frmvalidator.addValidation("email2","req");
frmvalidator.addValidation("email2","email");
</script>
</form>
</body>
</html>

and the file gen_validatorv2.js contains

/*
-------------------------------------------------------------------------
JavaScript Form Validator
Version 2.0.2
Copyright 2003 JavaScript-coder.com. All rights reserved.
You use this script in your Web pages, provided these opening credit
lines are kept intact.
The Form validation script is distributed free from JavaScript-Coder.com

You may please add a link to JavaScript-Coder.com,
making it easy for others to find this script.
Checkout the Give a link and Get a link page:
http://www.javascript-coder.com/links/how-to-link.php

You may not reprint or redistribute this code without permission from
JavaScript-Coder.com.

JavaScript Coder
It precisely codes what you imagine!
Grab your copy here:
http://www.javascript-coder.com/
------------------------------------------------------------------------
-
*/
function DoCustomValidation()
{
var frm = document.forms["myform"];
if(frm.email.value != frm.email2.value)
{
alert('The Email and verified Email does not match!');
return false;
}
else
{
return true;
}
}

function Validator(frmname)
{
this.formobj=document.forms[frmname];
if(!this.formobj)
{
alert("BUG: couldnot get Form object "+frmname);
return;
}
if(this.formobj.onsubmit)
{
this.formobj.old_onsubmit = this.formobj.onsubmit;
this.formobj.onsubmit=null;
}
else
{
this.formobj.old_onsubmit = null;
}
this.formobj.onsubmit=form_submit_handler;
this.addValidation = add_validation;
this.setAddnlValidationFunction=set_addnl_vfunctio n;
this.clearAllValidations = clear_all_validations;
}
function set_addnl_vfunction(functionname)
{
this.formobj.addnlvalidation = functionname;
}
function clear_all_validations()
{
for(var itr=0;itr < this.formobj.elements.length;itr++)
{
this.formobj.elements[itr].validationset = null;
}
}
function form_submit_handler()
{
for(var itr=0;itr < this.elements.length;itr++)
{
if(this.elements[itr].validationset &&
!this.elements[itr].validationset.validate())
{
return false;
}
}
if(this.addnlvalidation)
{
str =" var ret = "+this.addnlvalidation+"()";
eval(str);
if(!ret) return ret;
}
return true;
}
function add_validation(itemname,descriptor,errstr)
{
if(!this.formobj)
{
alert("BUG: the form object is not set properly");
return;
}//if
var itemobj = this.formobj[itemname];
if(!itemobj)
{
alert("BUG: Couldnot get the input object named: "+itemname);
return;
}
if(!itemobj.validationset)
{
itemobj.validationset = new ValidationSet(itemobj);
}
itemobj.validationset.add(descriptor,errstr);
}
function ValidationDesc(inputitem,desc,error)
{
this.desc=desc;
this.error=error;
this.itemobj = inputitem;
this.validate=vdesc_validate;
}
function vdesc_validate()
{
if(!V2validateData(this.desc,this.itemobj,this.err or))
{
this.itemobj.focus();
return false;
}
return true;
}
function ValidationSet(inputitem)
{
this.vSet=new Array();
this.add= add_validationdesc;
this.validate= vset_validate;
this.itemobj = inputitem;
}
function add_validationdesc(desc,error)
{
this.vSet[this.vSet.length]=
new ValidationDesc(this.itemobj,desc,error);
}
function vset_validate()
{
for(var itr=0;itr<this.vSet.length;itr++)
{
if(!this.vSet[itr].validate())
{
return false;
}
}
return true;
}
function validateEmailv2(email)
{
// a very simple email validation checking.
// you can add more complex email checking if it helps
if(email.length <= 0)
{
return true;
}
var splitted = email.match("^(.+)@(.+)$");
if(splitted == null) return false;
if(splitted[1] != null )
{
var regexp_user=/^\"?[\w-_\.]*\"?$/;
if(splitted[1].match(regexp_user) == null) return false;
}
if(splitted[2] != null)
{
var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
if(splitted[2].match(regexp_domain) == null)
{
var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
if(splitted[2].match(regexp_ip) == null) return false;
}// if
return true;
}
return false;
}
function V2validateData(strValidateStr,objValue,strError)
{
var epos = strValidateStr.search("=");
var command = "";
var cmdvalue = "";
if(epos >= 0)
{
command = strValidateStr.substring(0,epos);
cmdvalue = strValidateStr.substr(epos+1);
}
else
{
command = strValidateStr;
}
switch(command)
{
case "req":
case "required":
{
if(eval(objValue.value.length) == 0)
{
if(!strError || strError.length ==0)
{
strError = objValue.name + " : Required Field";
}//if
alert(strError);
return false;
}//if
break;
}//case required
case "maxlength":
case "maxlen":
{
if(eval(objValue.value.length) > eval(cmdvalue))
{
if(!strError || strError.length ==0)
{
strError = objValue.name + " : "+cmdvalue+" characters
maximum ";
}//if
alert(strError + "\n[Current length = " +
objValue.value.length + " ]");
return false;
}//if
break;
}//case maxlen
case "minlength":
case "minlen":
{
if(eval(objValue.value.length) < eval(cmdvalue))
{
if(!strError || strError.length ==0)
{
strError = objValue.name + " : " + cmdvalue + " characters
minimum ";
}//if
alert(strError + "\n[Current length = " +
objValue.value.length + " ]");
return false;
}//if
break;
}//case minlen
case "alnum":
case "alphanumeric":
{
var charpos = objValue.value.search("[^A-Za-z0-9]");
if(objValue.value.length > 0 && charpos >= 0)
{
if(!strError || strError.length ==0)
{
strError = objValue.name+": Only alpha-numeric characters
allowed ";
}//if
alert(strError + "\n [Error character position " +
eval(charpos+1)+"]");
return false;
}//if
break;
}//case alphanumeric
case "num":
case "numeric":
{
var charpos = objValue.value.search("[^0-9]");
if(objValue.value.length > 0 && charpos >= 0)
{
if(!strError || strError.length ==0)
{
strError = objValue.name+": Only digits allowed ";
}//if
alert(strError + "\n [Error character position " +
eval(charpos+1)+"]");
return false;
}//if
break;
}//numeric
case "alphabetic":
case "alpha":
{
var charpos = objValue.value.search("[^A-Za-z]");
if(objValue.value.length > 0 && charpos >= 0)
{
if(!strError || strError.length ==0)
{
strError = objValue.name+": Only alphabetic characters
allowed ";
}//if
alert(strError + "\n [Error character position " +
eval(charpos+1)+"]");
return false;
}//if
break;
}//alpha
case "alnumhyphen":
{
var charpos = objValue.value.search("[^A-Za-z0-9\-_]");
if(objValue.value.length > 0 && charpos >= 0)
{
if(!strError || strError.length ==0)
{
strError = objValue.name+": characters allowed are
A-Z,a-z,0-9,- and _";
}//if
alert(strError + "\n [Error character position " +
eval(charpos+1)+"]");
return false;
}//if
break;
}
case "email":
{
if(!validateEmailv2(objValue.value))
{
if(!strError || strError.length ==0)
{
strError = objValue.name+": Enter a valid Email address
";
}//if
alert(strError);
return false;
}//if
break;
}//case email
case "lt":
case "lessthan":
{
if(isNaN(objValue.value))
{
alert(objValue.name+": Should be a number ");
return false;
}//if
if(eval(objValue.value) >= eval(cmdvalue))
{
if(!strError || strError.length ==0)
{
strError = objValue.name + " : value should be less than "+
cmdvalue;
}//if
alert(strError);
return false;
}//if
break;
}//case lessthan
case "gt":
case "greaterthan":
{
if(isNaN(objValue.value))
{
alert(objValue.name+": Should be a number ");
return false;
}//if
if(eval(objValue.value) <= eval(cmdvalue))
{
if(!strError || strError.length ==0)
{
strError = objValue.name + " : value should be greater than
"+ cmdvalue;
}//if
alert(strError);
return false;
}//if
break;
}//case greaterthan
case "regexp":
{
if(objValue.value.length > 0)
{
if(!objValue.value.match(cmdvalue))
{
if(!strError || strError.length ==0)
{
strError = objValue.name+": Invalid characters found ";
}//if
alert(strError);
return false;
}//if
}
break;
}//case regexp
case "dontselect":
{
if(objValue.selectedIndex == null)
{
alert("BUG: dontselect command for non-select Item");
return false;
}
if(objValue.selectedIndex == eval(cmdvalue))
{
if(!strError || strError.length ==0)
{
strError = objValue.name+": Please Select one option ";
}//if
alert(strError);
return false;
}
break;
}//case dontselect
}//switch
return true;
}
/*
Copyright 2003 JavaScript-coder.com. All rights reserved.
*/

The problem is that I get the following error Line:70 Error: Object
expected.

I have tryed always for this to work and looked through google but to no
vail Please can someone help.


Apr 20 '06 #1
2 4846

this one wrote:
I have the following code <script language="JavaScript" src="..\include\gen_validatorv2.js"
type="text/javascript"></script>
Use forward slashes '/' in the path.

Change all instance of
<SCRIPT language="JavaScript">


to

<SCRIPT type="text/javascript">

--
S.C.

Apr 20 '06 #2
JRS: In article <Ob******************@newsfe5-gui.ntli.net>, dated Thu,
20 Apr 2006 14:49:18 remote, seen in news:comp.lang.javascript, this one
<an**@hotmail.com> posted :
JavaScript Form Validator
Version 2.0.2
Copyright 2003 JavaScript-coder.com. All rights reserved.
You use this script in your Web pages, provided these opening credit
lines are kept intact.
The Form validation script is distributed free from JavaScript-Coder.com

You may please add a link to JavaScript-Coder.com,
making it easy for others to find this script.
Checkout the Give a link and Get a link page:
http://www.javascript-coder.com/links/how-to-link.php

You may not reprint or redistribute this code without permission from
JavaScript-Coder.com.


Did you obtain that permission?

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Apr 20 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: qsweetbee | last post by:
I have a form(fAddUsers) in my database. It is continue form for data entry. Some fields are required fields. Some are optional fields. There is 1 particular filed(TokenExpirationDate)on the form...
3
by: Navin | last post by:
Hello friends... On a single asp.net web page i have a single server-side form that contains a couple of user-controls. Each user control has its own functionality and contains server-side textbox...
2
by: Paul | last post by:
Hi, I hope somebody can help me with the following. (I have tried searching for a solution on the newsgroups but nothing is quite what I need. Feel free to point me in the direction of anything...
14
by: JNariss | last post by:
Hello, I am fairly new to asp and jscript and am now in the process of learning some form validation. I am taking one step at a time by validating each field and testing it before moving onto...
7
by: Ladysniper | last post by:
DESPERATE doesn't begin to describe it. Can someone PLEASE tell me what is WRONG with this code? Now..a bit of background. It is a search results page for http://www.azsoma.info/directory.htm....
36
by: aljamala | last post by:
Hi, I keep getting this warning on a page, but I do not know what the problem is...does anyone have an idea about what could be wrong? line 88 column 7 - Warning: missing </formbefore <td> it...
0
by: karen987 | last post by:
This is an email form on an ASP page. I want to add validation before it submits, The current validation only checks "name, email, and content" (server side) if the spaces are empty. I need to add...
2
by: Chad Lupkes | last post by:
Hi everyone, I need help with a simple form validation. The form I'm using has been the target of some spammers, and I'm wondering what else I can do. I have a very simple validation, checking...
1
by: lilbit02 | last post by:
Hi, I have a form that utilizes validation as most do via javascript. This form worked totaly fine until I needed to add a dynamic div now the validation doesn't work. It does work for the first...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.