C # RegEx. ismatch () Regular Expression Verification

Source: Internet
Author: User
Using system. text. regularexpressions; # enter a number in the region verification text box /// <summary> /// check whether the value is a number (including an integer and a decimal number) /// </Summary> /// <Param name = "str"> </param> /// <returns> </returns> Public static bool getnum (string Str) {return RegEx. ismatch (STR, @ "^ [-]? \ D + [.]? \ D * {1} quot ;);} # endregion # enter an integer in the region verification text box /// <summary> /// enter an integer in the verification text box /// </Summary> /// <Param name = "strnum"> input character </param> /// <returns> Returns a value of the bool type </returns> Public static bool validatenum (string strnum) {return RegEx. ismatch (strnum, "^ [0-9] * {1} quot ;);} # endregion # enter the date in the region verification text box /// <summary> /// determine the date /// </Summary> /// <Param name = "date"> </ param> // <returns> </returns> Public static B OOl isvaliddate (string date) {// verify the YYYY-MM-DD format, basically take the leap year and February and so on into consideration bool bvalid = RegEx. ismatch (date, @ "^ (1 [6-9] | [2-9] \ D) \ D {2})-(0? [1, 13578] | 1 [02])-(0? [1-9] | [12] \ d | 3 [01]) | (1 [6-9] | [2-9] \ D) \ D {2})-(0? [13456789] | 1 [012])-(0? [1-9] | [12] \ d | 30) | (1 [6-9] | [2-9] \ D) \ D {2 }) -0? 2-(0? [1-9] | 1 \ d | 2 [0-8]) | (1 [6-9] | [2-9] \ D) (0 [48] | [2468] [048] | [13579] [26]) | (16 | [2468] [048] | [3579] [26]) 00)-0? 2-29-) {1} quot;); Return (bvalid & date. compareto ("1753-01-01")> = 0); // combines the expression of the date verification for the year of the current year and the year of the new year, we get the final validation date format as the regular expression of the 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)} # endregion # enter the region verification text box as email // verify the public static bool isvalidemail (string strin) {return RegEx. ismatch (strin, @ "^ ([\ W-\.] +) @ (\ [0-9] {1, 3 }\. [0-9] {1, 3 }\. [0-9] {1, 3 }\.) | ([\ W-] + \.) +) ([A-Za-Z] {2, 4} | [0-9] {1, 3}) (\]?) {1} quot ;);} # endregion # enter the phone number in the region verification text box /// <summary> /// enter the phone number in the verification text box /// </Summary> /// <Param name =" strphone "> input string </param> // <returns> Returns a Boolean value </returns> Public static bool validatephone (string strphone) {return RegEx. ismatch (strphone, @ "\ D {3, 4}-\ D {7, 8 }");} # endregion # enter a fax number in the region verification text box /// <summary> /// enter a fax number in the verification text box /// </Summary> /// <Param name =" strfax "> input string </param> // <retur Ns> return a value of the bool type </returns> Public static bool validatefax (string strfax) {return RegEx. ismatch (strfax, @ "86-\ D {2, 3}-\ D {7, 8}") ;}# endregion: httpcontext. current. request. userhostaddress /// <summary> /// whether it is an IP address // </Summary> /// <Param name = "ip"> </param> // <returns> </returns> Public static bool isip (string IP) {return RegEx. ismatch (httpcontext. current. request. userhostaddress, @ "^ (2 [0-4] \ D | 25 [0-5] | [01]? \ D ?) \.) {3} (2 [0-4] \ d | 25 [0-5] | [01]? \ D ?) {1} quot;);} public static bool isipsect (string IP) {return RegEx. ismatch (httpcontext. current. request. userhostaddress, @ "^ (2 [0-4] \ d | 25 [0-5] | [01]? \ D ?) \.) {2} (2 [0-4] \ d | 25 [0-5] | [01]? \ D? | \ *) \.) (2 [0-4] \ d | 25 [0-5] | [01]? \ D? | \ *) {1} quot ;);} /// <summary> /// determine whether the string is a YY-mm-dd string // </Summary> /// <Param name = "str"> string to be determined </param> // <returns> judgment result </returns> Public static bool isdatestring (string Str) {return RegEx. ismatch (STR, @ "(\ D {4})-(\ D {1, 2})-(\ D {1, 2 })");}
 string str1 = txtkaishi.Text.Trim();                string str2 = txtjieshu.Text.Trim();                Boolean result1 = Regex.IsMatch(str1, @"^(?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)$");                Boolean result2 = Regex.IsMatch(str2, @"^(?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-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.