I have a file that has a set of timestamps and I look for a way to filter them and find the wrong formatted from the well formatted by using a regex expression :
$line = array(20171203124500,20150120183045,20140621064431);
$args = array('filter' => FILTER_VALIDATE_REGEXP,
'options' => array('regexp' => 'REGEX-HERE'), );
$result = filter_var_array($line, $args);
var_dump($result);
I also want to check if the day of the month is correct :
- the date 31 April should not match
- the date 29/02/2003 should not match and 29/02/2004 should.
I have this expression :
^(?:(?:(?:0?[1-9]|1\d|2[0-8])\/(?:0?[1-9]|1[0-2]))\/(?:(?:1[6-9]|[2-9]\d)\d{2}))$|^(?:(?:(?:31\/0?[13578]|1[02])|(?:(?:29|30)\/(?:0?[1,3-9]|1[0-2])))\/(?:(?:1[6-9]|[2-9]\d)\d{2}))$|^(?:29\/0?2\/(?:(?:(?:1[6-9]|[2-9]\d)(?:0[48]|[2468][048]|[13579][26]))))$
But it is given for dates with this format : 31/01/2001
This expression validates dates in the Brazilian d/m/y format (from 1/1/1600 - 12/31/9999). The days are validated for the given month and year. Leap years are validated for all 4 digits years from 1600-9999. Days and months must be 1 or 2 digits and may have leading zeros. Years must be 4 digit years, between 1600 and 9999. Date separator must be a slash (/)
How to adapt this regexp to match the format I look for : YYYYmmddHHMMSS