Home > Backend Development > PHP Tutorial > Date Validation Regular Expression_PHP Tutorial

Date Validation Regular Expression_PHP Tutorial

WBOY
Release: 2016-07-13 10:57:55
Original
1748 people have browsed it

Date validation regular expression Three date verification regular expressions are provided below. You can choose one of the following three mid-term date verification methods according to your needs

Date verification regular expressions
Three date verification regular expressions are provided below. You can choose one of the following three mid-term date verification methods according to your needs
*/

$arr_date = array(
'2004-06-01',
'2005-0x-10',
'12-12-12',
'2000-12-25 00:10:20',
'2007-12-05'
);

for ($i=0; $i<5; ++$i)
{
$date = $arr_date[$i];
if(ereg("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})", $date, $regs))
{
echo "The date string $date conforms to the 'yyyy-mm-dd' format:";
echo "$regs[1].$regs[2].$regs[3]

";
}
else
{
echo "Date string $date is a date string that does not conform to the 'yyyy-mm-dd' format

";
}
}

//Match yyyy-mm-dd


(([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9 ][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12] [0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[ 1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})(0[48]|[2468][048]| [13579][26])|((0[48]|[2468][048]|[3579][26])00))-02-29)

//2: Match dd/mm/yyyy or match d/m/yyyy

'/^(([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|'
.'[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})/((([13578]|1[2] )|(0[13578]|1[02])'
.'/((0[1-9]|[12][0-9]|3[01])|([1-9]|[12][0-9]|3[1]))) |(((0[469]|11)|([469]|11))'
                  .'/((0[1-9]|[12][0-9]|30)|([1-9]|[12][0-9]|30)))|'
.'((02|2)/((0[1-9]|[1][0-9]|2[0-8])|([1-9]|[1][0-9] |2[0-8]))'
.')))|((([0-9]{2})((0[48]|[2468][048]|[13579][26])|([48]|[2468][048 ]|[13579][26]))|'
.'((((0[48])|([48]))|[2468][048]|[3579][26])00))/(02|2)/29)$/';

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632053.htmlTechArticleDate Validation Regular Expressions Three date validation regular expressions are provided below. You can choose according to your needs. One of the following three mid-term date verification methods date verification regular table...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template