hi all,
I have the following function that uses a regular expression to match a "00am - 00am" time format. Some examples would be; "8am - 12pm" or "10am - 2pm".
function checkTimeBlock(value, colname){
var value, colname, regexp, data;
var regexp = /^(1[012]|[1-9])[a|p]m - (1[012]|[1-9])[a|p]m$/i;
if ( !( regexp.test( value ) ) ) {
return [false,colname + ': Invalid format, try "00am - 00pm".'];
}else{
return [true,""];
}
}
It works but it's not very flexible. I'd like to also do the following:
1. remove any leading and trailing spaces.
2. remove any spaces from between "00" and "am" or "00" and "pm".
3. make sure that only one space is on either side of the dash so that " -" or "- " or "-" gets converted into " - ".
4. replace Upper case "AM" or "PM" to lower case "am" or "pm".
Can this be done in the expression?
thanks.