C # Regular Expression verification,

Source: Internet
Author: User
Tags valid email address

C # Regular Expression verification,

Public class VerifyUtil {// <summary> // judge that the input string contains only Chinese characters /// </summary> /// <param name = "input"> </ param> // <returns> </returns> public static bool IsChineseCh (string input) {return Regex. isMatch (input, @ "^ [\ u4e00-\ u9fa5] + $");} // <summary> // the phone number that matches the three-digit or four-digit area code, the area code can be enclosed in parentheses, // or not. The area code and the local code can be separated by a hyphen or space, /// or no interval // \ (0 \ d {2} \) [-]? \ D {8} | 0 \ d {2} [-]? \ D {8} | \ (0 \ d {3} \) [-]? \ D {7} | 0 \ d {3} [-]? \ D {7} /// </summary> /// <param name = "input"> </param> /// <returns> </returns> public static bool isPhone (string input) {string pattern = "^ \ (0 \ d {2} \) [-]? \ D {8 }$ | ^ 0 \ d {2} [-]? \ D {8 }$ | ^ \ (0 \ d {3} \) [-]? \ D {7 }$ | ^ 0 \ d {3} [-]? \ D {7} $ "; return Regex. isMatch (input, pattern );} /// <summary> /// determines whether the input string is a valid mobile phone number. /// </summary> /// <param name = "input"> </param> /// <returns> </returns> public static bool IsMobilePhone (string input) {return Regex. isMatch (input, @ "^ 1 {3, 5, 8} \ d {9} $ ");} /// <summary> /// determines that the input string only contains numbers. /// it can match integers and floating-point numbers. /// ^ -? \ D + $ | ^ (-? \ D +) (\. \ d + )? $ // </Summary> /// <param name = "input"> </param> /// <returns> </returns> public static bool IsNumber (string input) {string pattern = @ "^ -? \ D + $ | ^ (-? \ D +) (\. \ d + )? $ "; Return Regex. isMatch (input, pattern );} /// <summary> /// determines whether the input string is a valid Email address. /// </summary> /// <param name = "input"> </param >/// <returns> </returns> public static bool IsEmail (string input) {string pattern = @ "^ ([\ w-\.] +) @ (\ [0-9] {1, 3 }\. [0-9] {1, 3 }\. [0-9] {1, 3 }\.) | ([\ w-] + \.) +) ([a-zA-Z] {2, 4} | [0-9] {1, 3}) (\]?) $ "; Return Regex. isMatch (input, pattern );} /// <summary> /// determines whether the input string is a hyperlink. /// </summary> /// <param name = "input"> </param> // /<returns> </returns> public static bool IsURL (string input) {string pattern = @ "^ [a-zA-Z] +: // (\ w + (-\ w + )*)(\. (\ w + (-\ w + )*))*(\? \ S *)? $ "; Return Regex. IsMatch (input, pattern );}}

 

Related Article

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.