Its not working. I don't know regEx, but I need use it.
if ($('input[name="due_date"]').val().match("^(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\\d\\d$")) {
$('input[name="due_date"]').after("<span class='v_error'>Must fill</span>");
}
Its not working. I don't know regEx, but I need use it.
if ($('input[name="due_date"]').val().match("^(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\\d\\d$")) {
$('input[name="due_date"]').after("<span class='v_error'>Must fill</span>");
}
Share
Improve this question
edited Mar 4, 2012 at 8:16
Alan Moore
75.3k13 gold badges107 silver badges161 bronze badges
asked Aug 24, 2011 at 7:21
GereltodGereltod
2,2348 gold badges29 silver badges39 bronze badges
2
-
Could you be more specific about “not working”? Maybe you just need to insert
.value
in front of.match
? – Christopher Creutzig Commented Aug 24, 2011 at 7:28 - 1 Can i ask why you need to use regex? This is better left to date and not regex. too many corner cases. Check this post out stackoverflow./questions/511439/… – Matt Commented Aug 24, 2011 at 7:30
3 Answers
Reset to default 3$('input[name="due_date"]').val().match.......
A regex is surrounded with slashes. I just found that your regex is incorrect, too... So, coupled with the jQuery error pointed out by xdazz:
$('input[name="due_date"]').val().match(/^(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d$/);
The regex is from this website.
You're trying to match with the HTML object, you might add .val() after the jQuery Selector, like
$('input[name="due_date"]').val().match(/^(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\\d\\d$/);