![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Aug 2005
Posts: 66
Rep Power: 0
![]() |
Regular Exp help
Yo all! ^_^
I'm trying to make a reg exp that will match a users inputed time. I want the RE to match a string like 8:00am or 12:00pm. My version of the RE is as follows: var regEx = new RegExp ("(1-12):(0)*(0-60)(am|pm)")But...of course...it dosen't work. It ALWAYS returns false. (I'm not great with RE... ) Can I get some help? And just to point out, I want the test to fail if it is not in the form (x)x:xx(am|pm). Thanks a lot! ^_^ |
|
|
|
|
|
#2 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
You can only use hyphens to say "everything between these two" in character sets ([ ]):
(0?[1-9]|1[0-2]):([0-5][0-9])(am|pm) |
|
|
|
|
|
#3 |
|
Programmer
Join Date: Aug 2005
Posts: 66
Rep Power: 0
![]() |
Say, that's pretty cool. ^_^ The only problem that it runs into is that it accepts a time like 92341:00pm. Interestingly enough, it dosen't except 1:324324pm. I don't see any real difference in the re that casues the first part to not act as expected but the second part to be fine....strange...
Last edited by MegaArcon; Dec 7th, 2005 at 2:15 PM. |
|
|
|
|
|
#4 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Yo all! ^_^
You need to put some restrictions on the number of things that can match before the parser moves on and looks farther, dontchano.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#5 |
|
Hobbyist Programmer
Join Date: Nov 2005
Posts: 122
Rep Power: 3
![]() |
Just add the beginning/end symbols on:
^(0?[1-9]|1[0-2]):([0-5][0-9])(am|pm)$ --47.
__________________
"I'm going to become rich and famous when I invent a device that allows you to stab people in the face over the internet" |
|
|
|
|
|
#6 |
|
Programmer
Join Date: Aug 2005
Posts: 66
Rep Power: 0
![]() |
Yup, that did the trick Agent. Thanks all! ^_^ This forum rules all!
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|