SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    May 2002
    Location
    Newcastle, England
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    form validation date rexexp

    Why wont the following code validate my form data?
    PHP Code:
    if(ereg("^(\d{2}-){2}\d{4}$"$formFieldArray['date'])) {
      
    jsAlert("good date");
     }else {
      
    jsError("You did not enter a valid date!\\nPlease try again using the format dd-mm-yyyy.");
     } 
    Can anyone spot if ive done something wrong
    WINDOWS XP
    IE 6
    1280x1024
    BROADBAND

  2. #2
    SitePoint Wizard Chris82's Avatar
    Join Date
    Mar 2002
    Location
    Osnabrück
    Posts
    1,003
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi.

    Your regexp looks a bit strange ){2} means "))"

    try:

    PHP Code:
    if(preg_match("#^\d{2}-\d{2}-\d{4}$#"$formFieldArray['date'])) {
      
    jsAlert("good date" );
    }else {
      
    jsError("You did not enter a valid date!\\nPlease try again using the format dd-mm-yyyy." );

    This would force the user to enter the date in

    dd-mm-yyyy


Bookmarks

Posting Permissions

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