I'm trying to validate a date input by the use of regex.
if(!preg_match("/^[0-9]{4}\/[0-9]{2}\/[0-9]{2}$/", $_POST['variant']['sales_start'])) {
echo "invalid";
}
The string I'm trying to input is 2011-02-03, however it's failing, and I can't seem to figure out why.
Can someone please tell me what I'm doing wrong?
Thanks in advance
You're separating the date with dashes and the regex is looking for slashes?
Try
if ( !preg_match( "/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/", $_POST['variant']['sales_start'] ) )
{
echo "invalid";
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With