Javascript Regex for date almost works, but is also catching string like 1.11.111.11, how can I prevent this?
-
I am working on a regex and I think i'm about 90 % of the way there. I want it to match (which it seems to do fine): 2010 2010/01/30 2010/10/30 02:40 2010/10/30 02:40:20 2010/10/30 02:40:20 AM 2010/10/30 02:40:20 PM 2010-01-30 2010-10-30 02:40 2010-10-30 02:40:20 2010-10-30 02:40:20 AM 2010-10-30 02:40:20 PM I don't want it to match (or any other combination of strings delimited by periods): 1.11.111.11 Here is some test code I was running in chrome developer ( after the ... that yahoo answers is inserting I have s+([ap]m|[AP]M)|\d\d/). var test = "1.11.111.11"; test.match(/^(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])(19|20)\d\d[- /.](0[1-9]|1[0-2]):[0-5][0-9]\s+([ap]m|[… Returns: ["11", undefined, undefined, undefined, undefined, undefined] var test = "1.11.111.11"; test.match(/^(0[1-9]|1[012])[- /](0[1-9]|[12][0-9]|3[01])(19|20)\d\d[- /](0[1-9]|1[0-2]):[0-5][0-9]\s+([ap]m|[A… Returns; ["11", undefined, undefined, undefined, undefined, undefined] How can I modify the regex to not get that (or similar) period delimited strings? Thanks for your help!
-
Answer:
your character set [-/.] means you're searching for three cases: a hyphen a slash or a period try [-/]
bryce at Yahoo! Answers Visit the source
Related Q & A:
- How can I prevent memory warning in IOS?Best solution by cultofmac.com
- How can I prevent varicose veins?Best solution by Yahoo! Answers
- How can I prevent the flu?Best solution by Yahoo! Answers
- How can I prevent Google Talk from disconnecting?Best solution by Android Enthusiasts
- How can I prevent people from seeing my msn profile?Best solution by au.answers.yahoo.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.