Share instances of multiple C # common regular expressions

Source: Internet
Author: User
Using System;  Using System.Text.RegularExpressions;  namespace Commontools {/**////<summary>///Regexlib Summary description. </summary> public class Regexlib {//Verify email address public static bool IsValidEmail (string strin) {//Return T  Rue if Strin is in valid e-mail format. 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}) (\]?)  $");  } The date form of//dd-mm-yy instead of the Mm/dd/yy date form. public static string Mdytodmy (string input) {return Regex.Replace (input, "\\b (? \\d{1,2})/(? \\d{1,2})/(? \\d{2,4}) \\b",  "${day}-${month}-${year}"); }//Verify whether it is a decimal public static bool Isvaliddecimal (string strin) {return Regex.IsMatch (strin,@ "[0].\d{1,2}|[  1] "); }//Verify is the phone number public static bool Isvalidtel (string strin) {return Regex.IsMatch (strin,@ "(\d+-)? (  \d{4}-?\d{7}|\d{3}-?\d{8}|^\d{7,8}) (-\d+)? "); Verify that the month and day public static bool Isvaliddate (string strin) {return Regex.IsMatch (strin,@ "^2\d{3}-(?: 0?) [1-9]|1[0-2])-(?: 0?) [1-9]| [1-2]\d|3[0-1]) (?: 0?) [1-9]|1\d|2[0-3]):(?: 0? [1-9]| [1-5]\d]:(?: 0? [1-9]|  [1-5]\d) $ "); }//Verify the suffix name public static bool Isvalidpostfix (string strin) {return regex.ismatch (strin,@ "\.  i:gif|jpg) $ ");  }//Verify if the character is between 4 and 12 public static bool Isvalidbyte (string strin) {return Regex.IsMatch (strin,@ "^[a-z]{4,12}$"); }//Verify IP public static bool Isvalidip (string strin) {return Regex.IsMatch (strin,@ "^ (\d{1,2}|1\d\d|2[0-4]\d|25[0-5]) \. (\d{1,2}|1\d\d|2[0-4]\d|25[0-5]) \. (\d{1,2}|1\d\d|2[0-4]\d|25[0-5]) \.  (\d{1,2}|1\d\d|2[0-4]\d|25[0-5]) $ "); }  }  }

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.