1. Introduction
Many times we need to use some verification methods. Sometimes when we need to use regular expressions to verify the data, we often need to search online for a long time, but the results are not very consistent with what we want. So I shared the verification help categories I have sorted out. I will share them here, leave a brief for myself, and also provide reference for friends in need.
2. Verification fragments
2.1 Email Verification
#region IsEmail (email address)/// <summary> /// Whether to email/// </summary> /// <param name="value">Email Address</param>/// <param name="isRestrict">Whether to verify in strict mode</param>/// <returns></returns> public static bool IsEmail(string value, bool isRestrict=false) { if (()) { return false; } string pattern = isRestrict ? @"^(?("")("".+?""@)|(([0-9a-zA-Z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-zA-Z])@))(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,6}))$" : @"^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$"; return (pattern, ); } /// <summary> /// Is there an email address/// </summary> /// <param name="value">value</param>/// <param name="isRestrict">Whether to verify in strict mode</param>/// <returns></returns> public static bool HasEmail(string value, bool isRestrict = false) { if (()) { return false; } string pattern = isRestrict ? @"^(?("")("".+?""@)|(([0-9a-zA-Z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-zA-Z])@))(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,6}))$" : @"^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$"; return (pattern, ); }
2.2 Mobile phone number verification
#region IsPhoneNumber (Is it a legal mobile number)/// <summary> /// Is it a legal mobile number/// </summary> /// <param name="value">Mobile number</param>/// <returns></returns> public static bool IsPhoneNumber(string value) { if (()) { return false; } return (@"^(0|86|17951)?(13[0-9]|15[012356789]|18[0-9]|14[57]|17[678])[0-9]{8}$"); } #endregion #region IsMobileNumber (Whether is the mobile number)/// <summary> /// Is the mobile phone number/// </summary> /// <param name="value">Mobile number</param>/// <param name="isRestrict">Whether to verify in strict mode</param>/// <returns></returns> public static bool IsMobileNumberSimple(string value, bool isRestrict = false) { if (()) { return false; } string pattern=isRestrict ? @"^[1][3-8]\d{9}$" : @"^[1]\d{10}$"; return (pattern); } /// <summary> /// Is the mobile phone number/// </summary> /// <param name="value">Mobile number</param>/// <returns></returns> public static bool IsMobileNumber(string value) { if (()) { return false; } value = ().Replace("^", "").Replace("$", ""); /** * phone number: * 13[0-9], 14[5,7], 15[0, 1, 2, 3, 5, 6, 7, 8, 9], 17[6, 7, 8], 18[0-9], 170[0-9] * Mobile number segment: 134,135,136,137,138,139,150,151,152,157,158,159,182,183,184,187,188,147,178,1705 * Unicom number segment: 130,131,132,155,156,185,186,145,176,1709 * Electric signal segment: 133,153,180,181,189,177,1700 */ return (@"^1(3[0-9]|4[57]|5[0-35-9]|8[0-9]|70)\d{8}$"); } /// <summary> /// Is there a mobile phone number/// </summary> /// <param name="value">value</param>/// <param name="isRestrict">Whether to verify in strict mode</param>/// <returns></returns> public static bool HasMobileNumberSimple(string value, bool isRestrict = false) { if (()) { return false; } string pattern = isRestrict ? @"[1][3-8]\d{9}" : @"[1]\d{10}"; return (pattern); } #endregion #region IsChinaMobilePhone (Is it China Mobile Number)/// <summary> /// Is it a Chinese mobile number/// </summary> /// <param name="value">Mobile number</param>/// <returns></returns> public static bool IsChinaMobilePhone(string value) { if (()) { return false; } /** * China Mobile: China Mobile * 134,135,136,137,138,139,150,151,152,157,158,159,182,183,184,187,188,147,178,1705 */ return (@"(^1(3[4-9]|4[7]|5[0-27-9]|7[8]|8[2-478])\d{8}$)|(^1705\d{7}$)"); } #endregion #region IsChinaUnicomPhone (Is China Unicom number)/// <summary> /// Whether China Unicom number/// </summary> /// <param name="value">Mobile number</param>/// <returns></returns> public static bool IsChinaUnicomPhone(string value) { if (()) { return false; } /** * China Unicom: China Unicom * 130,131,132,155,156,185,186,145,176,1709 */ return (@"(^1(3[0-2]|4[5]|5[56]|7[6]|8[56])\d{8}$)|(^1709\d{7}$)"); } #endregion #region IsChinaTelecomPhone (Is it Chinese electronic signal code)/// <summary> /// Is it a Chinese electronic signal code/// </summary> /// <param name="value">Mobile number</param>/// <returns></returns> public static bool IsChinaTelecomPhone(string value) { if (()) { return false; } /** * China Telecom: China Telecom * 133,153,180,181,189,177,1700 */ return (@"(^1(33|53|77|8[019])\d{8}$)|(^1700\d{7}$)"); }
2.3 Identity card verification
#region IsIdCard (Is the ID number)/// <summary> /// Is the ID number/// </summary> /// <param name="value">ID card</param>/// <returns></returns> public static bool IsIdCard(string value) { if (()) { return false; } if ( == 15) { return (@"^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$"); } return == 0x12 && (@"^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$", ); }
2.4 Base64 encoding verification
#region IsBase64String (Is Base64 encoded)/// <summary> /// Is Base64 encoding?/// </summary> /// <param name="value">Base64 string</param>/// <returns></returns> public static bool IsBase64String(string value) { return (@"[A-Za-z0-9\+\/\=]"); }
2.5 Time verification
#region IsDate (date)/// <summary> /// Is it date/// </summary> /// <param name="value">Date string</param>/// <param name="isRegex">Whether to be regular verification</param>/// <returns></returns> public static bool IsDate(string value,bool isRegex=false) { if (()) { return false; } if (isRegex) { // Considering the 4-year 366 days, there is also a special February date return ( @"^((((1[6-9]|[2-9]\d)\d{2})-(0?[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-)) (20|21|22|23|[0-1]?\d):[0-5]?\d:[0-5]?\d$"); } DateTime minValue; return (value, out minValue); } /// <summary> /// Is it date/// </summary> /// <param name="value">Date string</param>/// <param name="format">Format string</param>/// <returns></returns> public static bool IsDate(string value, string format) { return IsDate(value, format, null, ); } /// <summary> /// Is it date/// </summary> /// <param name="value">Date string</param>/// <param name="format">Format string</param>/// <param name="provider">Format provider</param>/// <param name="styles">Date format</param>/// <returns></returns> public static bool IsDate(string value, string format, IFormatProvider provider, DateTimeStyles styles) { if (()) { return false; } DateTime minValue; return (value, format, provider, styles, out minValue); } #endregion #region IsDateTime (Is it valid time)/// <summary> /// Is it greater than the minimum time/// </summary> /// <param name="value">Time</param>/// <param name="min">minimum time</param>/// <returns></returns> public static bool IsDateTimeMin(string value, DateTime min) { if (()) { return false; } DateTime dateTime; if ((value, out dateTime)) { if ((dateTime, min) >= 0) { return true; } } return false; } /// <summary> /// Is it less than the maximum time/// </summary> /// <param name="value">Time</param>/// <param name="max">Maximum time</param>/// <returns></returns> public static bool IsDateTimeMax(string value, DateTime max) { if (()) { return false; } DateTime dateTime; if ((value, out dateTime)) { if ((max, dateTime) >= 0) { return true; } } return false; }
2.6 Url Verification
#region IsUrl (whether the Url address is it)/// <summary> /// Whether to address Url (unified resource location)/// </summary> /// <param name="value">url address</param>/// <returns></returns> public static bool IsUrl(string value) { if (()) { return false; } return ( @"^(http|https)\://([a-zA-Z0-9\.\-]+(\:[a-zA-Z0-9\.&%\$\-]+)*@)*((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])|localhost|([a-zA-Z0-9\-]+\.)*[a-zA-Z0-9\-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{1,10}))(\:[0-9]+)*(/($|[a-zA-Z0-9\.\,\?\'\\\+&%\$#\=~_\-]+))*$", ); } #endregion #region IsUri(Uri or not)/// <summary> /// Whether Uri (Unified resource identification)/// </summary> /// <param name="value">uri</param> /// <returns></returns> public static bool IsUri(string value) { if (()) { return false; } if ((".", ) == -1) { return false; } var schemes = new[] { "file", "ftp", "gopher", "http", "https", "ldap", "mailto", "", "", "news", "nntp", "telnet", "uuid" }; bool hasValidSchema = false; foreach (string scheme in schemes) { if (hasValidSchema) { continue; } if ((scheme, )) { hasValidSchema = true; } } if (!hasValidSchema) { value = "http://" + value; } return (value, ); } #endregion #region IsMainDomain(Is the main domain name)/// <summary> /// Whether it is the main domain name or the domain name starting with www/// </summary> /// <param name="value">url address</param>/// <returns></returns> public static bool IsMainDomain(string value) { if (()) { return false; } return ( @"^http(s)?\://((www.)?[a-zA-Z0-9\-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{1,10}))(\:[0-9]+)*(/($|[a-zA-Z0-9\.\,\?\'\\\+&%\$#\=~_\-]+))*$"); } #endregion
2.7 Basic format verification
#region IsGuid (Guid)/// <summary> /// Is it Guid/// </summary> /// <param name="guid">Guid string</param>/// <returns></returns> public static bool IsGuid(string guid) { if (()) { return false; } return (@"[A-F0-9]{8}(-[A-F0-9]{4}){3}-[A-F0-9]{12}|[A-F0-9]{32}", ); } #endregion #region IsPositiveInteger (Is it greater than 0 positive integer)/// <summary> /// Is it a positive integer greater than 0/// </summary> /// <param name="value">Positive integer</param>/// <returns></returns> public static bool IsPositiveInteger(string value) { if (()) { return false; } return (@"^[1-9]+\d*$"); } #endregion #region IsInt32 (Is Int32 type or not)/// <summary> /// Is Int32 type?/// </summary> /// <param name="value">Integer</param>/// <returns></returns> public static bool IsInt32(string value) { if (()) { return false; } return (@"^[0-9]*$"); } #endregion #region IsDouble (Is it Double type, if with. Default is 1 bit 0)/// <summary> /// Is it Double type/// </summary> /// <param name="value">decimal</param>/// <returns></returns> public static bool IsDouble(string value) { if (()) { return false; } return (@"^\d[.]?\d?$"); } /// <summary> /// Is it Double type/// </summary> /// <param name="value">decimal</param>/// <param name="minValue">Minimum value</param>/// <param name="maxValue">Maximum value</param>/// <param name="digit">Decimal places, if it is 0, it will not be detected</param>/// <returns></returns> public static bool IsDouble(string value, double minValue, double maxValue, int digit) { if (()) { return false; } string patten = (@"^\d[.]?\d{0}$", "{0,10}"); if (digit > 0) { patten = (@"^\d[.]?\d{0}$", "{" + digit + "}"); } if ((patten)) { double val = (value); if (val >= minValue && val <= maxValue) { return true; } } return false; } #endregion #region IsInteger(Is it integer or not)/// <summary> /// Is it integer/// </summary> /// <param name="value">value</param>/// <returns>Result</returns>public static bool IsInteger(string value) { if (()) { return false; } return (@"^\-?[0-9]+$"); } #endregion #region IsUnicode (Is it a Unicode string)/// <summary> /// Whether to Unicode string/// </summary> /// <param name="value">unicode string</param>/// <returns>Result</returns>public static bool IsUnicode(string value) { if (()) { return false; } return ( @"^(http|https|ftp|rtsp|mms):(\/\/|\\\\)[A-Za-z0-9%\-_@]+\.[A-Za-z0-9%\-_@]+[A-Za-z0-9\.\/=\?%\-&_~`@:\+!;]*$"); } #endregion #region IsDecimal(Is it digital)/// <summary> /// Is it digital?/// </summary> /// <param name="value">number</param>/// <returns></returns> public static bool IsDecimal(string value) { if (()) { return false; } return (@"^([0-9])[0-9]*(\.\w*)?$"); } #endregion
2.8 IP and Mac address verification
#region IsMac (Mac address)/// <summary> /// Whether to address Mac/// </summary> /// <param name="value">Mac address</param>/// <returns></returns> public static bool IsMac(string value) { if (()) { return false; } return (@"^([0-9A-F]{2}-){5}[0-9A-F]{2}$") || (@"^[0-9A-F]{12}$"); } #endregion #region IsIpAddress(Is it IP address)/// <summary> /// Is it an IP address/// </summary> /// <param name="value">ip address</param>/// <returns>Result</returns>public static bool IsIpAddress(string value) { if (()) { return false; } return (@"^(\d(25[0-5]|2[0-4][0-9]|1?[0-9]?[0-9])\d\.){3}\d(25[0-5]|2[0-4][0-9]|1?[0-9]?[0-9])\d$"); }
2.9 String Verification
#region IsVersion (whether the version number is valid)/// <summary> /// Whether the version number is valid, examples: 1.3, 1.1.5, 1.25.256/// </summary> /// <param name="value">version number</param>/// <param name="length">Length</param>/// <returns></returns> public static bool IsVersion(string value, int length = 5) { if (()) { return false; } value = ("^", "").Replace("$", ""); return ((@"^{0}{1}{2}$", @"\d{0,4}\.(\d{1,4}\.){0,", length, @"}\d{1,4}")); } #endregion #region IsContainsChinese (whether it contains Chinese)/// <summary> /// Is it Chinese or not/// </summary> /// <param name="value">Chinese</param>/// <returns></returns> public static bool IsChinese(string value) { if (()) { return false; } return (@"^[\u4e00-\u9fa5]+$", ); } /// <summary> /// Whether it contains Chinese/// </summary> /// <param name="value">Chinese</param>/// <returns></returns> public static bool IsContainsChinese(string value) { if (()) { return false; } return (@"[\u4e00-\u9fa5]+",); } #endregion #region IsContainsNumber (whether it contains numbers)/// <summary> /// Whether to include numbers/// </summary> /// <param name="value">number</param>/// <returns></returns> public static bool IsContainsNumber(string value) { if (()) { return false; } return (@"[0-9]+"); } #endregion #region IsLengthStr(Is the string length within the specified range)/// <summary> /// Is the string length within the specified range? One Chinese is 2 characters/// </summary> /// <param name="value">String</param>/// <param name="begin">Start</param>/// <param name="end">End</param>/// <returns></returns> public static bool IsLengthStr(string value, int begin, int end) { int length = (value, @"[^\x00-\xff]", "OK").Length; if ((length <= begin) && (length >= end)) { return false; } return true; } #endregion #region IsNormalChar (Is it normal characters, combination of letters, numbers, and underscores)/// <summary> /// Is it normal characters, combinations of letters, numbers, and underscores/// </summary> /// <param name="value">String</param>/// <returns></returns> public static bool IsNormalChar(string value) { if (()) { return false; } return (@"[\w\d_]+", ); } #endregion #region IsPostfix (whether to specify a suffix)/// <summary> /// Whether to specify a suffix/// </summary> /// <param name="value">String</param>/// <param name="postfixs">Array of suffixes</param>/// <returns></returns> public static bool IsPostfix(string value, string[] postfixs) { if (()) { return false; } string postfix = ("|", postfixs); return ((@".(?i:{0})$", postfix)); } #endregion #region IsRepeat(Does it be repeated)/// <summary> /// Whether to repeat, example: 112, return true/// </summary> /// <param name="value">value</param>/// <returns></returns> public static bool IsRepeat(string value) { if (()) { return false; } var array = (); return (c => (t => t == c) > 1); }
2.10 Postal Code Verification
#region IsPostalCode (PostalCode or not)/// <summary> /// Whether it is the postal code, 6 digits/// </summary> /// <param name="value">Zip Code</param>/// <returns></returns> public static bool IsPostalCode(string value) { if (()) { return false; } return (@"^[1-9]\d{5}$", ); }
2.11 Chinese landline verification
#region IsTel (Is it Chinese phone number)/// <summary> /// Is it a Chinese phone number, format: 010-85849685/// </summary> /// <param name="value">Tel</param>/// <returns></returns> public static bool IsTel(string value) { if (()) { return false; } return (@"^\d{3,4}-?\d{6,8}$", ); }
2.12 QQ number verification
#region IsQQ (Is it legal QQ number)/// <summary> /// Is it legal QQ number/// </summary> /// <param name="value">QQ number</param>/// <returns></returns> // ReSharper disable once InconsistentNaming public static bool IsQQ(string value) { if (()) { return false; } return (@"^[1-9][0-9]{4,9}$"); } #endregion
3. Source code
Finally, the source code address is attached
/jianxuanbing/JCE/blob/master//
4. Regular expressions
4.1 Verify the expression of numbers
Number: ^[0-9]*$
n-digit number: ^\d{n}$
Numbers with at least n digits: ^\d{n,}$
Number of m-n bits: ^\d{m,n}$
Numbers starting with zero and non-zero: ^(0|[1-9][0-9]*)$
Numbers with a maximum of two decimal places starting with non-zero: ^([1-9][0-9]*)+(.[0-9]{1,2})?$
Positive or negative numbers with 1-2 decimal places: ^(\-)?\d+(\.\d{1,2})?$
Positive, negative, and decimal: ^(\-|\+)?\d+(\.\d+)?$
Positive real numbers with two decimals: ^[0-9]+(.[0-9]{2})?$
Positive real numbers with 1 to 3 decimal places: ^[0-9]+(.[0-9]{1,3})?$
Nonzero positive integer: ^[1-9]\d*$ or ^([1-9][0-9]*){1,3}$ or ^\+?[1-9][0-9]*$
Negative integers with nonzero: ^\-[1-9][]0-9"*$ or ^-[1-9]\d*$
Non-negative integer: ^\d+$ or ^[1-9]\d*|0$
Non-positive integer: ^-[1-9]\d*|0$ or ^((-\d+)|(0+))$
Non-negative floating point number: ^\d+(\.\d+)?$ or ^[1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0$
Non-positive floating point number: ^((-\d+(\.\d+)?)|(0+(\.0+)?))$ or ^(-([1-9]\d*\.\d*|0\.\d*[1-9]\d*))|0?\.0+|0$
Positive floating point number: ^[1-9]\d*\.\d*|0\.\d*[1-9]\d*$ or ^(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*))$
Negative floating point number: ^-([1-9]\d*\.\d*|0\.\d*[1-9]\d*)$ or ^(-(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*))$
Floating point number: ^(-?\d+)(\.\d+)?$ or ^-?([1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0)$
4.2 Verify character expressions
Chinese characters: ^[\u4e00-\u9fa5]{0,}$
English and numbers: ^[A-Za-z0-9]+$ or ^[A-Za-z0-9]{4,40}$
All characters with lengths of 3-20: ^.{3,20}$
A string composed of 26 English letters: ^[A-Za-z]+$
A string consisting of 26 capital English letters: ^[A-Z]+$
A string consisting of 26 lowercase English letters: ^[a-z]+$
String consisting of numbers and 26 English letters: ^[A-Za-z0-9]+$
String consisting of numbers, 26 English letters or underscores: ^\w+$ or ^\w{3,20}$
Chinese, English, and numbers include underscores: ^[\u4E00-\u9FA5A-Za-z0-9_]+$
Chinese, English, numbers but not underscores and other symbols: ^[\u4E00-\u9FA5A-Za-z0-9]+$ or ^[\u4E00-\u9FA5A-Za-z0-9]{2,20}$
You can enter characters such as ^%&',;=?$\": [^%&',;=?$\x22]+
The input of characters containing ~ is prohibited: [^~\x22]+
4.3 Special requirements expressions
Email address: ^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$
Domain name: [a-zA-Z0-9][-a-zA-Z0-9]{0,62}(/.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+/.?
InternetURL: [a-zA-z]+://[^\s]* or ^http://([\w-]+\.)+[\w-]+(/[\w-./?%&=]*)?$
Mobile phone number: ^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$
Phone Numbers ("XXX-XXXXXXXXX", "XXXX-XXXXXXXXX", "XXX-XXXXXXXXXX", "XXXXXXXXXXXXX, "XXXXXXXXXXXXXX): ^(\(\d{3,4}-)|\d{3.4}-)?\d{7,8}$
Domestic phone number (0511-4405222, 021-87888822): \d{3}-\d{8}|\d{4}-\d{7}
ID number (15 digits, 18 digits): ^\d{15}|\d{18}$
Short ID number (number, letter ending x): ^([0-9]){7,18}(x|X)?$ or ^\d{8,18}|[0-9x]{8,18}|[0-9X]{8,18}?$
Is the account legal (beginning with letters, 5-16 bytes allowed, alphanumeric underscores allowed): ^[a-zA-Z][a-zA-Z0-9_]{4,15}$
Password (starting with letters, lengths between 6 and 18, can only contain letters, numbers and underscores): ^[a-zA-Z]\w{5,17}$
Strong password (must contain a combination of upper and lower case letters and numbers, special characters cannot be used, the length is between 8-10): ^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,10}$
Date format: ^\d{4}-\d{1,2}-\d{1,2}
12 months of a year (01-09 and 1-12): ^(0?[1-9]|1[0-2])$
31 days of a month (01-09 and 1-31): ^((0?[1-9])|((1|2)[0-9])|30|31)$
Money input format:
xml file: ^([a-zA-Z]+-?)+[a-zA-Z0-9]+\\.[x|X][m|M][l|L]$
Regular expression of Chinese characters: [\u4e00-\u9fa5]
Double-byte characters: [^\x00-\xff] (Including Chinese characters, it can be used to calculate the length of a string (one double-byte character length meter 2, ASCII character meter 1))
Regular expression for blank lines: \n\s*\r (can be used to delete blank lines)
Regular expressions for HTML tags: <(\S*?)[^>]*>.*?</\1>|<.*? /> (The version circulated on the Internet is too bad, and the above is only partial, and I still can't do anything about complex nested tags)
Regular expressions of the beginning and end whitespace characters: ^\s*|\s*$ or (^\s*)|(\s*$) (It can be used to delete whitespace characters at the end of the line (including spaces, tabs, page breaks, etc.), a very useful expression)
Tencent QQ number: [1-9][0-9]{4,} (Tencent QQ number starts at 10000)
China Postal Code: [1-9]\d{5}(?!\d) (China Postal Code is 6 digits)
IP address: \d+\.\d+\.\d+\.\d+ (It is useful when extracting IP address)
IP address: ((?:(?:(?:25[0-5]|2[0-4]\\d|[01]?\\d?\\d)\\.){3}(?:25[0-5]|2[0-4]\\d|[01]?\\d?\\d))
4.4 Money input format
There are four forms of money that we can accept: "10000.00" and "10,000.00", and "10,000" without "subdivision":^[1-9][0-9]*$
This means any number that does not start with 0, but this also means that a character "0" does not pass, so we take the following form: ^(0|[1-9][0-9]*)$
A 0 or a number that does not start with 0. We can also allow a minus sign to start with: ^(0|-?[1-9][0-9]*)$
This means a 0 or a number that may be negative and not 0. Let the user start with 0. Remove the negative sign, because money cannot be negative. What we want to add below is the decimal part that explains the possible: ^[0-9]+(.[0-9]+)? $
It must be noted that there should be at least one digit after the decimal point, so "10." does not pass, but "10" and "10.2" pass: ^[0-9]+(.[0-9]{2})?$
In this way, we stipulate that there must be two digits after the decimal point. If you think it is too harsh, you can do this: ^[0-9]+(.[0-9]{1,2})?$
This allows the user to write only one decimal. Now we should consider the commas in the number, we can do this: ^[0-9]{1,3}(,[0-9]{3})*(.[0-9]{1,2})?$
1 to 3 numbers, followed by any comma + 3 numbers, the comma becomes optional, instead of having to: ^([0-9]+|[0-9]{1,3}(,[0-9]{3})*)(.[0-9]{1,2})?$
Note: This is the final result. Don't forget that "+" can be replaced with "*" if you think empty strings are acceptable (strange, why?) Finally, don't forget to remove the backslash when using functions. The general errors are here.
The above is the regular expression of C# verification help that the editor introduced to you. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support for my website!