Detailed description of Regular Expressions for Date Format Verification

Source: Internet
Author: User

---- Annual subscription ----------------------

// ********************** Year fan quota 0001-9999 ********** ***************
// [1-9]/d {3} The number of thousands is greater than 0
/// D [1-9]/d {2} Hundreds of digits greater than 0
/// D {2} [1-9]/D 10 digits greater than 0
/// D {3} [1-9] digits greater than 0
// Finally: [1-9]/d {3} |/d [1-9]/d {2} |/d {2} [1-9]/d |/d {3} [1-9]
// ******************* The number of days in which the month is 1-31 for 1, 5, 7, 8, 10, and 12 is 1-31 days, mm-dd ******************
// (0 [1, 13578] | 1 [02]) // (0 [1-9] | [12]/d | 3 [01])
// ******************* The number of days for the month is-30, MM-dd *********************
// (0 [469] | 11) // (0 [1-9] | [12]/d | 30)
// ********************* Month is 2, consider the normal year, MM-dd *****************************
// 02 // (0 [1-9 | 1/d | 2 [0-8])

// The formula for the year-on-year table is as follows: ([1-9]/d {3} |/d [1-9]/d {2} |/d {2} [1 -9]/d |/d {3} [1-9]) // (0 [13578] | 1 [02]) // (0 [1-9] | [12]/d | 3 [01]) | (0 [469] | 11) // (0 [1-9] | [12]/d | 30 )) | (02 // (0 [1-9 | 1/d | 2 [0-8])

---- Considering the leap year ----------------------

// ********************* Leap year considerations, ****************
/// D {2} (0 [48] | [13579] [26] | [2468] [048])
// ******************* The year in which a person can be divisible by 400 in a leap year. The number that can be divisible by 400 is certainly 100, so the last two must be 00. We only need to ensure that the first two can be divisible by four.
// (0 [48] | [2468] [048] | [3579] [26]) 00
// ********************* In February, MM-dd ************************************* **
// 02 // (0 [1-9] | [12]/d)

// The statement of the year of renewal is as follows: (/d {2} (0 [48] | [13579] [26] | [2468] [048]) | (0 [48] | [2468] [048] | [3579] [26]) 00) // (0 [13578] | 1 [02]) // (0 [1-9] | [12]/d | 3 [01]) | (0 [469] | 11) // (0 [1-9] | [12]/d | 30) | (02 // (0 [1-9] | [12]/d )))

 

// The final result is:

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

The above is a regular expression in the format of 2010/09/09.

If you want to change the format to 2010-10-10, you only need to replace // /-.

 

 

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.