ahhhh, regex; the one thing we all try our hardest to avoid despite their overwhelming power.
i got hold of a regex online from
http://www.felgall.com/php17.htm and i want to match dates in the yyyy-mm-dd format.
the code below is just returning false every time, can anyone see why..?
$regexPattern = "^(19|20)\d{2}[\/\.- ](0?[1-9]|1[0-2])[\/\.- ](0?[1-9]|[12][0-9]|3[01])$";
if(trim($postArray[$this->data]) != "") {
if(!preg_match("/" . $regexPattern . "/", trim($postArray[$this->data]))) {
return FALSE;
} else {
if($this->dataType == "time") {
return (string) $this->data . ":00";
} else {
return (string) $this->data;
}
}
} else {
return FALSE;
}
hmmm, just turned on error reporting & got
Warning: preg_match() [function.preg-match]: Compilation failed: range out of order in character class at offset 19
in the meantime, i shall google further...