www.webdeveloper.com
Results 1 to 5 of 5

Thread: I need help on a numeric validation.

  1. #1
    Join Date
    Mar 2006
    Posts
    4

    Unhappy I need help on a numeric validation.


    I need to validate a date, DD/MM/YYYY, also, DD must be in 01 to 31 range and MM on 01 to 12 range

    could someone please tell me how to do it... it's kinda urgent and I'm new to Javascript .. plz?

  2. #2
    Join Date
    Nov 2003
    Location
    Worthington, OH, USA
    Posts
    3,634
    Off the top of my head
    Code:
    function testDate(inputDate){
    var tDate=new Date(inputDate.substr(0,2),inputDate.substr(3,2),inputDate.substr(6,4));
    if (tDate.getMonth()+1 == inputDate.substr(0,2) && tDate.getDate() ==  inputDate.substr(3,2) && tDate.getFullYear() == inputDate.substr(6,4) ) 
    alert("Valid Date");
    }
    Might be a typo or two in there, but should be close.
    54 68 65 42 65 61 72 4D 61 79

  3. #3
    Join Date
    Mar 2006
    Posts
    4
    can't i validate it using regular expressions????

  4. #4
    Join Date
    Nov 2003
    Location
    Worthington, OH, USA
    Posts
    3,634
    Quote Originally Posted by betoelbicho
    can't i validate it using regular expressions????
    How would a regular expression know if February should have 28 or 29 days?
    54 68 65 42 65 61 72 4D 61 79

  5. #5
    Join Date
    Mar 2003
    Posts
    575
    This proves I need to be locked up.

    (((0[1-9]|[12][0-9]|30)/(0[13-9]|1[012])|(31/(0[13578]|1[02]))|((0[1-9]|1[0-9]|2[0-8])/02)))/[0-9]{4}|(29/02/(([02468][048]|[13579][26])00|[0-9]{2}(0[48]|[13579][26]|[2468][048])))

    Does this do the job? Does it actually work?

    I just found a place to test it, and edited it to remove a bug.
    Another bug fix-- man, this isn't easy!
    By George, I think I've got it!
    Last edited by Juuitchan; 03-17-2006 at 08:54 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles