Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help with a script 1

Status
Not open for further replies.

baronne

Technical User
May 31, 2003
166
Hi,
can anyone help me with a simple bit of javascript?
I need to modify the following code for a date of birth selector to return false if they date of birth is less than 18 years old.


jQuery.validator.addMethod("validDOB", function (str1, element) {

var mon1 = parseInt(str1.substring(0,2),10);
var dt1 = parseInt(str1.substring(3,5),10);
var yr1 = parseInt(str1.substring(6,10),10);
var date1 = new Date(parseInt(yr1), parseInt(mon1)-1, parseInt(dt1));
var date2 = new Date();
if(date2 < date1)
{
return false;
}
else
{
return true;
}
}, "Please enter valid date of birth");


:: baronne
------------------
"lekker, shot bru
 
[&nbsp;]
I am assuming that str1 is the date of birth.

If so, try this:

[blue]var yr1 = parseInt(str1.substring(6,10),10)[red] + 18[/red];[/blue]



mmerlinn


Poor people do not hire employees. If you soak the rich, who are you going to work for?

"We've found by experience that people who are careless and sloppy writers are usually also careless and sloppy at thinking and coding. Answering questions for careless and sloppy thinkers is not rewarding." - Eric Raymond
 
cheers! I'll give that a whirl....

:: baronne
------------------
"lekker, shot bru
 
champion that worked a treat! nice and simple fix!!

:: baronne
------------------
"lekker, shot bru
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top