Super Regular Expression validation Date and Time

Source: Internet
Author: User
Regular Expressions play an important role in verification. The following are my regular functions for verifying the time:

Public   Bool Mytime ( String Str)
{
Bool Flag = False ;
String RegEx =   @" ^ (\ D {2} ([02468] [048]) | ([13579] [26]) [\-\/\ s]? (0? [13578]
) | (1 [02]) [\-\/\ s]? (0? [1-9]) | ([1-2] [0-9]) | (3 [01]) | (0? [4
69]) | (11) [\-\/\ s]? (0? [1-9]) | ([1-2] [0-9]) | (30) | (0? 2 [\-\/\
S]? (0? [1-9]) | ([1-2] [0-9]) | (\ D {2} ([02468] [1235679]) | ([1
3579] [01345789]) [\-\/\ s]? (0? [13578]) | (1 [02]) [\-\/\ s]? ((
0? [1-9]) | ([1-2] [0-9]) | (3 [01]) | (0? [469]) | (11) [\-\/\ s]? ((
0? [1-9]) | ([1-2] [0-9]) | (30) | (0? 2 [\-\/\ s]? (0? [1-9]) | (1 [0-9]
) | (2 [0-8]) " ; // Date
RegEx + =   @" (\ S (0? [0-9]) | ([1-2] [0-3]) \ :( [0-5]? [0-9]) (\ s) | (\ :( [0-5]? [0-9])? $ " ; // Time part
Regexoptions options = (Regexoptions. ignorepatternwhitespace | Regexoptions. multiline) | Regexoptions. ignorecase );
RegEx Reg =   New RegEx (RegEx, options );
If (Reg. ismatch (STR ))
{
Flag=True;
}
Return Flag;
}

The regular expression can accurately verify whether the entered time is correct and verify the leap year.

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.