M
Mick Walker
Hi,
I have a problem that I have been trying to figure for a couple of days,
and am wondering if anyone out there would be so kind as to give me a
solution. (Deadline time)
I am trying to validate a form. Its quite a simple form, but I am a wee
bit stuck. Baically it consists of 9 text input fields and a select
element. All elements on the form, have to have a value in them
(manditory), BUT 2 items (txtEmail, and txtDOB) have to match a certian
criteria.
The first is obvious, it has to be a valid email address, the second
however is a lot mroe difficult. The dob entered, not only have to be a
valid date, it has to make the user over 18, otherwise the form wont submit.
I am a ASP.Net programmer, but due to time resrictions we are updating
an existing project using classic asp (which I have never used) were it
asp.net I would simply handle this problem server side (lot of resources
I know), but that isnt an option for me. Plus I could do with learning a
little more than the bard Basics of Javascript.
At the moment I am using 3 different function, one to validate the date,
one to validate the email, and another to make sure all elements contain
a value.
These are like so:
function validateDate(fld) {
var RegExPattern =
/^((((0?[1-9]|[12]\d|3[01])[\.\-\/](0?[13578]|1[02])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|[12]\d|30)[\.\-\/](0?[13456789]|1[012])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|1\d|2[0-8])[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|(29[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00)))|(((0[1-9]|[12]\d|3[01])(0[13578]|1[02])((1[6-9]|[2-9]\d)?\d{2}))|((0[1-9]|[12]\d|30)(0[13456789]|1[012])((1[6-9]|[2-9]\d)?\d{2}))|((0[1-9]|1\d|2[0-8])02((1[6-9]|[2-9]\d)?\d{2}))|(2902((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00))))$/;
var errorMessage = 'Please enter valid date as month, day, and four
digit year.\nYou may use a slash, hyphen or period to separate the
values.\nThe date must be a real date. 30/2/2000 would not be
accepted.\nFormat dd/mm/yyyy.';
if ((fld.value.match(RegExPattern)) && (fld.value!='')) {
} else {
alert(errorMessage);
fld.focus();
return false;
}
}
function validateWinStuffForm(f)
{
if(!valid_Required(f)){
alert('The form was filled out incorrectly');
return false;
}
}
function valid_Email(t) {
if(!r_validEmail.test(t)) {
alert('Please enter a valid email address');
return false;
}
return true;
}
I would like one function, that takes the form as an argument and does
all of these checks. The names of the DOB and Email fields will always
be the same on any form which the function is used (as the forms are
generated server side).
I hope someone can help
Kind Regards
Mick Walker
I have a problem that I have been trying to figure for a couple of days,
and am wondering if anyone out there would be so kind as to give me a
solution. (Deadline time)
I am trying to validate a form. Its quite a simple form, but I am a wee
bit stuck. Baically it consists of 9 text input fields and a select
element. All elements on the form, have to have a value in them
(manditory), BUT 2 items (txtEmail, and txtDOB) have to match a certian
criteria.
The first is obvious, it has to be a valid email address, the second
however is a lot mroe difficult. The dob entered, not only have to be a
valid date, it has to make the user over 18, otherwise the form wont submit.
I am a ASP.Net programmer, but due to time resrictions we are updating
an existing project using classic asp (which I have never used) were it
asp.net I would simply handle this problem server side (lot of resources
I know), but that isnt an option for me. Plus I could do with learning a
little more than the bard Basics of Javascript.
At the moment I am using 3 different function, one to validate the date,
one to validate the email, and another to make sure all elements contain
a value.
These are like so:
function validateDate(fld) {
var RegExPattern =
/^((((0?[1-9]|[12]\d|3[01])[\.\-\/](0?[13578]|1[02])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|[12]\d|30)[\.\-\/](0?[13456789]|1[012])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|1\d|2[0-8])[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|(29[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00)))|(((0[1-9]|[12]\d|3[01])(0[13578]|1[02])((1[6-9]|[2-9]\d)?\d{2}))|((0[1-9]|[12]\d|30)(0[13456789]|1[012])((1[6-9]|[2-9]\d)?\d{2}))|((0[1-9]|1\d|2[0-8])02((1[6-9]|[2-9]\d)?\d{2}))|(2902((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00))))$/;
var errorMessage = 'Please enter valid date as month, day, and four
digit year.\nYou may use a slash, hyphen or period to separate the
values.\nThe date must be a real date. 30/2/2000 would not be
accepted.\nFormat dd/mm/yyyy.';
if ((fld.value.match(RegExPattern)) && (fld.value!='')) {
} else {
alert(errorMessage);
fld.focus();
return false;
}
}
function validateWinStuffForm(f)
{
if(!valid_Required(f)){
alert('The form was filled out incorrectly');
return false;
}
}
function valid_Email(t) {
if(!r_validEmail.test(t)) {
alert('Please enter a valid email address');
return false;
}
return true;
}
I would like one function, that takes the form as an argument and does
all of these checks. The names of the DOB and Email fields will always
be the same on any form which the function is used (as the forms are
generated server side).
I hope someone can help
Kind Regards
Mick Walker