Jump to content

What the h#ll?!


LostOblivion

Recommended Posts

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.)

[code]
$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. =(" );
[/code]

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:

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

Tell me what?! Ahh, you got the "Jay." eh? =) It's weird.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.