Jump to content


Photo

What the h#ll?!


  • Please log in to reply
1 reply to this topic

#1 LostOblivion

LostOblivion
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 21 August 2006 - 08:28 PM

Hey. First time post here I think. I'm making this calendar and I'm trying to parse a time format from an input field - when I suddenly hit a wall.

What I'm trying to do here is to get the hours and minutes off of a string such as

2:50
02:50
2 50
02 50
2.50
02.50
250
0250
2
02

All of the above can be entered by the user and I've come up with a regex I think works to do this job. (All of the above can be read as 2 hours and 50 minutes by a human right? (Except for the bottom two which are 2 hours.) And I'm sure this regex works since I've tested it with ereg.)

$regex = "^([0-9]?[0-9])(:|\.| )?([0-9][0-9])?$";
if ( preg_match( $regex, $_POST['user_field_goes_here'], $matches ) )
 die( "Ok...it works." );
else
 die( "Nope. Still no good result. =(" );

But when I try to get the groups into $matches array the function returns false?!?!?! Heck it does so even without the $matches array as an argument.

The problem is I always get the sad smiley, ok! =S Is there something weird about this function or what?

I mean. Try running this:

$regex = "^([0-9]?[0-9])(:|\.| )?([0-9][0-9])?$";
if ( ereg( $regex, $_POST['user_field_goes_here'] ) )
 die( "Jay." );
else
 die( "No." );

Tell me what?! Ahh, you got the "Jay." eh? =) It's weird.

#2 LostOblivion

LostOblivion
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 21 August 2006 - 08:36 PM

Heh. I guess I'm a little tired. Forgot the delimitors. |=[

< n00bie

[ PROBLEM SOLVED ]




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users