473,836 Members | 2,235 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help with form validation with gen_validatorv2 .js (desperate)

I have the following code

<html>
<head>
<title>Untitl ed Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaS cript" src="..\include \gen_validatorv 2.js"
type="text/javascript"></script>
</head>

<body bgcolor="#FFFFF F" 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">ema il:
<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">ema il2:
<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="JavaS cript">
var frmvalidator = new Validator("myfo rm");
frmvalidator.se tAddnlValidatio nFunction("DoCu stomValidation" );
frmvalidator.ad dValidation("em ail","req");
frmvalidator.ad dValidation("em ail","email");
frmvalidator.ad dValidation("em ail2","req");
frmvalidator.ad dValidation("em ail2","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 DoCustomValidat ion()
{
var frm = document.forms["myform"];
if(frm.email.va lue != frm.email2.valu e)
{
alert('The Email and verified Email does not match!');
return false;
}
else
{
return true;
}
}

function Validator(frmna me)
{
this.formobj=do cument.forms[frmname];
if(!this.formob j)
{
alert("BUG: couldnot get Form object "+frmname);
return;
}
if(this.formobj .onsubmit)
{
this.formobj.ol d_onsubmit = this.formobj.on submit;
this.formobj.on submit=null;
}
else
{
this.formobj.ol d_onsubmit = null;
}
this.formobj.on submit=form_sub mit_handler;
this.addValidat ion = add_validation;
this.setAddnlVa lidationFunctio n=set_addnl_vfu nction;
this.clearAllVa lidations = clear_all_valid ations;
}
function set_addnl_vfunc tion(functionna me)
{
this.formobj.ad dnlvalidation = functionname;
}
function clear_all_valid ations()
{
for(var itr=0;itr < this.formobj.el ements.length;i tr++)
{
this.formobj.el ements[itr].validationset = null;
}
}
function form_submit_han dler()
{
for(var itr=0;itr < this.elements.l ength;itr++)
{
if(this.element s[itr].validationset &&
!this.elements[itr].validationset. validate())
{
return false;
}
}
if(this.addnlva lidation)
{
str =" var ret = "+this.addnlval idation+"()";
eval(str);
if(!ret) return ret;
}
return true;
}
function add_validation( itemname,descri ptor,errstr)
{
if(!this.formob j)
{
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.val idationset)
{
itemobj.validat ionset = new ValidationSet(i temobj);
}
itemobj.validat ionset.add(desc riptor,errstr);
}
function ValidationDesc( inputitem,desc, error)
{
this.desc=desc;
this.error=erro r;
this.itemobj = inputitem;
this.validate=v desc_validate;
}
function vdesc_validate( )
{
if(!V2validateD ata(this.desc,t his.itemobj,thi s.error))
{
this.itemobj.fo cus();
return false;
}
return true;
}
function ValidationSet(i nputitem)
{
this.vSet=new Array();
this.add= add_validationd esc;
this.validate= vset_validate;
this.itemobj = inputitem;
}
function add_validationd esc(desc,error)
{
this.vSet[this.vSet.lengt h]=
new ValidationDesc( this.itemobj,de sc,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_u ser) == null) return false;
}
if(splitted[2] != null)
{
var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
if(splitted[2].match(regexp_d omain) == null)
{
var regexp_ip =/^\[\d{1,3}\.\d{1,3 }\.\d{1,3}\.\d{ 1,3}\]$/;
if(splitted[2].match(regexp_i p) == null) return false;
}// if
return true;
}
return false;
}
function V2validateData( strValidateStr, objValue,strErr or)
{
var epos = strValidateStr. search("=");
var command = "";
var cmdvalue = "";
if(epos >= 0)
{
command = strValidateStr. substring(0,epo s);
cmdvalue = strValidateStr. substr(epos+1);
}
else
{
command = strValidateStr;
}
switch(command)
{
case "req":
case "required":
{
if(eval(objValu e.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(objValu e.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(objValu e.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 "alphanumer ic":
{
var charpos = objValue.value. search("[^A-Za-z0-9]");
if(objValue.val ue.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.val ue.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.val ue.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 "alnumhyphe n":
{
var charpos = objValue.value. search("[^A-Za-z0-9\-_]");
if(objValue.val ue.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(!validateEma ilv2(objValue.v alue))
{
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(objVal ue.value))
{
alert(objValue. name+": Should be a number ");
return false;
}//if
if(eval(objValu e.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 "greatertha n":
{
if(isNaN(objVal ue.value))
{
alert(objValue. name+": Should be a number ");
return false;
}//if
if(eval(objValu e.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.val ue.length > 0)
{
if(!objValue.va lue.match(cmdva lue))
{
if(!strError || strError.length ==0)
{
strError = objValue.name+" : Invalid characters found ";
}//if
alert(strError) ;
return false;
}//if
}
break;
}//case regexp
case "dontselect ":
{
if(objValue.sel ectedIndex == null)
{
alert("BUG: dontselect command for non-select Item");
return false;
}
if(objValue.sel ectedIndex == 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 4898

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

Change all instance of
<SCRIPT language="JavaS cript">


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.c om> 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.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.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
4040
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 which is depended on the other field(TokenID)whether it is blank or not. If the "TokenID" field is blank, the "TokenExpirationDate" field can be blank also. But if the "TokenID" field is not blank or null, the "TokenExpirationDate" field must be...
3
5269
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 controls, requiredfieldvalidator controls which validate the textboxes, and a linkbutton control that postbacks the web page. The problem is, when the user clicks on the linkbutton control on one user control, the requiredfieldvalidator gets...
2
1635
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 I may have missed though.) I have a form with 2 text boxes, two list boxes and 2 buttons (A & B). Both buttons must perform some validation but they differ in their extent. Button A must ensure that a date has been entered in both text
14
2162
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 the next one to be sure I am correct. I ran into a problem with my validation when I added an else if code to my code. Here is what I tried to do: Form (ITTermination) has a field (EmployeeName) which I would like to validate to check for no...
7
1692
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. (use Scottsdale for the city) If you go look, you see that the search results post (I do have my table borders up for debugging) but it doesn't line up with the table above it...the whole scroll background doesn't show up and I cannot get
36
3117
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 highlights this line: <form name="frmCurrency" action="" method="post"> Page source....
0
1343
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 the following so that the form is not submitted unless the following is true. 1. The "name" field must be maximum 20 characters. Not left empty. Letters only. 2. The "email" must be a valid email. Not left empty. 3. The "subject" must be maximum...
2
1469
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 for blanks, and found an additional zipcode validation form here: http://javascript.internet.com/forms/val-zip-code.html I tried combining them, and it doesn't seem to be working. I'm not
1
1622
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 dropdown but nothing there after. I always get the error saying is null or not an object. I need help trying to figure out how to access the ojects in this form. Now in my body I have a <form> and it's name is form1 and I also have another <form>...
0
10823
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10532
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10577
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10243
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7775
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5812
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4443
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4003
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3103
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.