Format date: MMM D[,] YYYY
[,] – optional comma and may be some space . Example:
Nov 12, 2000 - true
Nov 12 2000 - true
Nov 12, 2000 - true
Nov 12, 2000 true
My regExp:/^(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\ *(\d{1,2})\,? *(\d{4})$/
But if value – March 2010 all if true
My function for check value
function checkDateWithStringMonth1(value) {
//reset
resetDate();
//set min and max date
var minYear = 1900;
//var maxYear = (new Date()).getFullYear();
// regular expression to match required date format
re = /^(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\ *(\d{1,2})\,? *(\d{4})$/;
//check correct
if (value != '') {
if (regs = value.match(re)) {
if (regs[2] < 1 || regs[2] > 31) {
return false;
}
if(regs[3] < minYear){return false;}
} else { return false; }
} else { return false; }
//assign
return true;
}
Differences from your original:
\sinstead of [space] to handle different kinds of whitespace+instead of*:*means 0 or more, you want 1 or more,.Edit: To accomodate dates with no space after the comma:
(?:stats a non-capturing group.(?:,|\s)\s*: Allow for a comma or a whitespace character, and then possibly more whitespace.Test: