Regular Expression for date Verification

Source: Internet
Author: User

The regular expression for date verification provides three regular expressions for date verification. You can select one of the following three methods for date Verification Based on your needs.

Regular Expression for date Verification
The following provides three regular expressions for date verification. You can select one of the following three methods for date Verification Based on your needs.
*/
 

$ Arr_date = array (
'2017-06-01 ',
'2017-0x-10 ',
'12-12-12 ',
'2017-12-25 00:10:20 ',
'2017-2007'
);

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] <br/> ";
}
Else
{
Echo "<B> the date string $ date does not conform to the date string in 'yyyy-mm-dd' format </B> <br/> ";
}
}

// Match with 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 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) | ([1, 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) $ /';

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.