Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder ellisd5's Avatar
    Join Date
    Jun 2002
    Location
    Uk
    Posts
    160
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Regular Expression

    I have a bit of Javascript that is checking to see that a date is enter in this format DD/MM/YYYY
    sDate is the input field
    Code:
    if(isNaN(sDate.substring(0, 2)) || isNaN(sDate.substring(3, 5)) || isNaN(sDate.substring(6, 10)) || sDate.charAt(2) != "/" || sDate.charAt(5) != "/") {
    	alert("Date needs to be in format DD/MM/YYYY.");
    	return false;
    }
    Problem is I have been told that it must accept say 1/9/2004 which the above doesn't accept.

    Im rubbish at Regular Expressions, is there a regular expression that can do this check?

    TIA Dale
    Dale Ellis
    __________________

  • #2
    Regular Coder
    Join Date
    Mar 2003
    Posts
    241
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I had a similar topic not that long ago, anyhow, you can find if you try the lovely search engine.

    But since I am such a nice guy I'll provide the link to it

    liorean gave me an example and a very detailed explanation of how it works. It was extremely useful to me on my way of understanding regExp's and hopefully it will be just as useful to you too!

    RegExp - validate date
    http://www.codingforums.com/showthre...threadid=28920


  •  

    Posting Permissions

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