I'm trying to find a best way to test if a string fits a current criteria. Basically, I have a date coming in as such:
1/17/2013 12:00 AM
The month and day fields can be one or two digits, while the year is always four. The hour can be one or two digits. The minute field is always two digits For example, this is also applicable:
10/1/2013 1:00 AM
Right now, I have this regex, but it doesn't seem to be working:
/^(0[1-9]|1[0-2])\/(0[1-9]|[1-2][0-9]|3[0-1])\/(20[1-9][2-9]) (0[1-9]|1[0-2]):([0-5][0-9]) (am|pm)$/
I am using it as such:
$('input[name=targetMe]').each( function() {
alert('start')
if(/^(0[1-9]|1[0-2])\/(0[1-9]|[1-2][0-9]|3[0-1])\/(20[1-9][2-9]) (0[1-9]|1[0-2]):([0-5][0-9]) (AM|PM)$/.test($(this).val())) {
alert('passes')
} else {
alert('dont')
}
});
Is there something wrong with my current regex, or should I be using it in another way, or is there a better solution out there than this?