Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
193
rated 0 times [  198] [ 5]  / answers: 1 / hits: 112269  / 12 Years ago, sat, october 6, 2012, 12:00:00

I have a DateTime string ISO8601 formated


2012-10-06T04:13:00+00:00

and the following Regex which does not match this string


#(d{4})-(d{2})-(d{2})T(d{2}):(d{2}):(d{2})+(d{2}):(d{2})#

I can't figure out why it does not match.


I escaped metacharacters, for me it seems to be OK.


http://jsfiddle.net/5n5vk/2/


EDIT :


The right way: http://jsfiddle.net/5n5vk/3/


More From » regex

 Answers
246

Don't quote the regex when specifying a regex in js. Forward slash is enough.



alert($('#datepicker').val());

if($('#datepicker').val().match(
/(d{4})-(d{2})-(d{2})T(d{2}):(d{2}):(d{2})[+-](d{2}):(d{2})/
)) {
alert('ok');
} else {
alert('not ok');
}​

[#82726] Thursday, October 4, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
arlethjeanettep

Total Points: 506
Total Questions: 96
Total Answers: 79

Location: Liberia
Member since Tue, Mar 14, 2023
1 Year ago
;