Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 7th, 2005, 05:59 AM
Friend of Wrox
Points: 8,019, Level: 38
Points: 8,019, Level: 38 Points: 8,019, Level: 38 Points: 8,019, Level: 38
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2005
Location: Mauchline, East Ayrshire, Scotland
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default RegExp

Code:
///////////////////////////////////////
// CHILD Birthday Checker              //
///////////////////////////////////////
// DESCRIPTION:                         //
// CHECK IF THE DECLARED CHILD DOB   //
// IS LESS THAN 12 YEARS OLD         //
///////////////////////////////////////
function checkChdBirthday(obj)
    {
    df = document.form;
    retdate = df.retdt.value; // Return Date of Journey in YYYYMMDD format
    if(document.form.nochd.value==1)
    {
        nochdvalue=document.form.nochd.value
    }
    else
    {
        nochdvalue=document.form.nochd.value-1
    }

    for (i=0; i<nochdvalue; i++) // loop through the number of children
    {
    number=number+1;
    if( !/^(\d{1,2})(\d{1,2})(\d{4})$/.test(obj.value) )
    {
        alert( "Invalid date supplied - must be format DDMMYYYY" );
        return;
    }

    // pass Infant DOB to check_date to check for invalid dates
    // e.g. 30022002
    check_date(obj); 

    var d = new Date();
    var d2 = new Date(RegExp.$3, RegExp.$2, RegExp.$1);
    nochd = document.form.nochd.value
    noinf = document.form.noinf.value

    var diff = d.getDiff(d2, "y")
    if( isNaN(diff) )
    {
        alert( "Invalid date supplied" );
    }
    else if( diff < 12 ) {
        //alert( "This IS an CHILD \n they are younger than 12" );
        child = true;
        submit_form=true;
        under12counter = under12counter + 1;
        passtocheckRetDate = obj.value;
        checkRetDate(document.form.retdt);

    }
    else if( diff > 12 ) {
        //alert( "This is NOT an CHILD\nthey are older than 12" );
        child = false;
        submit_form=false;
        chdcounter = chdcounter + 1; // amount of declared children that are found to be under 12
        childno = i+1

        forename = document.form.cfname1.value
        surname = document.form.clname1.value

        if(chdcounter==2)
        {
            if(document.form.cfname2.value!="")
            {
                forename2 = document.form.cfname2.value
                surname2 = document.form.clname2.value
            }
        }

        if(chdcounter==3)
        {
            if(document.form.cfname3.value!="")
            {
                forename3 = document.form.cfname3.value
                surname3 = document.form.clname3.value
            }
        }
        }
    }    
    inf_ok=false;    
}
is there a way to change the above code to take into consideration
the date and the month when finding the difference in the two dates.

Something in the RegExp function?

www.crmpicco.co.uk
www.crmpicco.co.uk.tt
www.milklemonadechocolate.uk.tt
www.griswolds.uk.tt
www.piccosmini.co.uk.tt
www.morton.uk.tt
__________________
_______________________
Ayrshire Minis - a Mini E-Community
http://www.ayrshireminis.com
http://www.crmpicco.co.uk




Similar Threads
Thread Thread Starter Forum Replies Last Post
RegExp Problem Abbas Classic ASP Professional 0 August 2nd, 2006 10:48 AM
Regexp how to (also Urgent) NEO1976 Javascript 1 July 10th, 2006 08:54 AM
RegExp crmpicco Classic ASP Basics 0 June 6th, 2005 05:54 AM
RegExp Nitin_sharma Javascript 2 November 30th, 2004 07:21 AM
regexp problem godhsf80 PHP How-To 2 March 10th, 2004 04:54 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.