This post was last edited by QWERTYU on 2020-5-6 08:52
1. Check the expression of the number 1: Number: ^[0-9]*$ 2: A number with nth digits: ^\d{n}$ 3: A number with at least n digits: ^\d{n,}$ 4: Digits in the m-n digit: ^\d{m,n}$ 5: Numbers starting with zero and non-zero: ^(0|[ 1-9][0-9]*)$ 6: Numbers with up to two decimal places that do not start with zero: ^([1-9][0-9]*)+(.[ 0-9]{1,2})?$ 7: Positive or negative numbers with 1-2 decimal places: ^(\-)?\d+(\.\d{1,2})?$ 8: Positive, negative, and decimal: ^(\-|\+)?\d+(\.\d+)?$ 9: A positive real number with two decimal places: ^[0-9]+(.[ 0-9]{2})?$ 10: Positive real numbers with 1~3 decimal places: ^[0-9]+(.[ 0-9]{1,3})?$ 11: A positive integer that is not zero: ^[1-9]\d*$ or ^([1-9][0-9]*){1,3}$ or ^\+? [1-9] [0-9]*$ 12: A negative integer that is non-zero: ^\-[1-9][]0-9"*$ or ^-[1-9]\d*$ 13: Non-negative integers: ^\d+$ or ^[1-9]\d*|0$ 14: Non-positive integer: ^-[1-9]\d*|0$ or ^((-\d+)|( 0+))$ 15: Non-negative floating-point numbers: ^\d+(\.\d+)?$ or ^[1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0$ 16: Non-positive floating-point number: ^((-\d+(\.\d+)?)| (0+(\.0+)?)) $ or ^(-([1-9]\d*\.\d*|0\.\d*[1-9]\d*))|0?\.0+|0$ 17: 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]*)) $ 18: 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]*))) $ 19: Floating-point number: ^(-?\d+)(\.\d+)?$ or ^-? ([1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0)$
2. Expressions for verifying characters 1: Chinese characters: ^[\u4e00-\u9fa5]{0,}$ 2 : English and numeric: ^[A-Za-z0-9]+$ or ^[A-Za-z0-9]{4,40}$ 3: All characters with a length of 3-20: ^. {3,20}$ 4: A string consisting of 26 letters: ^[A-Za-z]+$ 5: A string consisting of 26 uppercase letters: ^[A-Z]+$ 6: A string consisting of 26 lowercase letters: ^[a-z]+$ 7: a string consisting of numbers and 26 letters: ^[A-Za-z0-9]+$ 8: A string consisting of numbers, 26 letters, or underscores: ^\w+$ or ^\w{3,20}$ 9: Chinese, English, numbers including underscores: ^[\u4E00-\u9FA5A-Za-z0-9_]+$ 10: Chinese, English, numbers but not underscores and other symbols: ^[\u4E00-\u9FA5A-Za-z0-9]+$ or ^[\u4E00-\u9FA5A-Za-z0-9]{2,20}$ 11: You can enter ^%&',; =?$\", etc.: [^%&',; =?$\x22]+ 12: Characters containing ~ are prohibited: [^~\x22]+
3. Special needs expressions
1: Email address: ^\w+([-+.] \w+)*@\w+([-.] \w+)*\.\w+([-.] \w+)*$ 2: Domain:[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(/.[ a-zA-Z0-9][-a-zA-Z0-9]{0,62})+/.? 3: InternetURL:[a-zA-z]+://[^\s]* or ^http://([\w-]+\.) +[\w-]+(/[\w-./?%&=]*)?$ 4: Mobile phone number: ^(13[0-9]|14[0-9]|15[0-9]|16[0-9]|17[0-9]|18[0-9]|19[0-9])\d{8}$ (Since the number release section of the Ministry of Industry and Information Technology is irregular, it is recommended to use pan-parsing ^([1][3,4,5,6,7,8,9])\d{9}$) 5: Phone numbers ("XXX-XXXXXXX", "XXXX-XXXXXXX", "XXX-XXXXXXX", "XXX-XXXXXXXX", "XXXXXXX", and "XXXXXXXX):^(\(\d{3,4}-)|\d{3.4}-)?\d{7,8}$ 6: Domestic phone numbers (0511-4405222, 021-87888822):\d{3}-\d{8}|\d{4}-\d{7} 7: 18-digit ID number (number, letter x ending): ^((\d{18})|( [0-9x] {18})| ([0-9X]{18})) $ 8: Whether the account number is legitimate (letter start, 5-16 bytes allowed, alphanumeric underscores allowed): ^[a-zA-Z][a-zA-Z0-9_]{4,15}$ 9: Password (starting with a letter, length between 6~18, can only contain letters, numbers and underscores): ^[a-zA-Z]\w{5,17}$ 10: Strong password (must contain a combination of uppercase and lowercase letters and numbers, no special characters, between 8-10 length): ^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])[\da-zA-Z]{8,10}$ 11: Date format: ^\d{4}-\d{1,2}-\d{1,2} 12: 12 months of a year (01~09 and 1~12):^(0?[ 1-9]|1[0-2])$ 13: 31 days of a month (01~09 and 1~31):^((0?[ 1-9])| ((1|2)[0-9])|30|31)$ 14: Input Format for Money: 1. There are four representations of money that we can accept: "10,000.00" and "10,000.00", and "10,000" and "10,000" without "points": ^[1-9][0-9]*$ 2. This represents any number that doesn't start with 0, however, it also means that a character "0" doesn't pass, so let's take the following form: ^(0|[ 1-9][0-9]*)$ 3. A 0 or a number that does not start with 0. We can also allow a minus sign at the beginning: ^(0|-?[ 1-9][0-9]*)$ 4. This indicates a 0 or a number that may start negative and does not start with 0. Let the user start with 0. Remove the negative sign as well, because money can't be negative. What we want to add below is the decimal part that illustrates the possible numbers: ^[0-9]+(.[ 0-9]+)?$ 5. It must be noted that there should be at least 1 digit after the decimal point, so "10." is not passed, but "10" and "10.2" are: ^[0-9]+(.[ 0-9]{2})?$ 6. In this way we stipulate that there must be two decimal places, if you think it is too harsh, you can do this: ^[0-9]+(.[ 0-9]{1,2})?$ 7. This allows the user to write only one decimal place. Now it's time to consider commas in numbers, we can do this: ^[0-9]{1,3}(,[0-9]{3})*(.[ 0-9]{1,2})?$ 8. 1 to 3 numbers, followed by any comma + 3 numbers, the comma becomes optional, not required: ^([0-9]+|[ 0-9]{1,3}(,[0-9]{3})*)(.[ 0-9]{1,2})?$ 23: Note: This is the end result, don't forget that "+" can be replaced with "*" if you think an empty string is also acceptable (weird, why?) Finally, don't forget to remove that backslash when using the function, the general mistakes are here 24: xml file:^([a-zA-Z]+-?) +[a-zA-Z0-9]+\\. [x|X] [m|M] [l|L]$ 25: Regular expressions for Chinese characters: [\u4e00-\u9fa5] 26: Double-byte characters: [^\x00-\xff] (including Chinese characters, can be used to calculate the length of a string (a double-byte character length meter of 2, ASCII character count of 1)) 27: Regular expression for blank rows: \n\s*\r (can be used to remove blank lines) 28: Regular expression for HTML markup: <(\S*?)[^>]*>.*?</\1>| <.*? /> (The version circulating on the Internet is too bad, the above one is only partial, and there is still nothing that can be done about complex nested markup) 29: Regular expression for first and last whitespaces: ^\s*|\s*$ or (^\s*)| (\s*$) (Very useful expressions that can be used to remove whitespace characters at the beginning and end of a line (including spaces, tabs, page breaks, etc.) 30: Tencent QQ number: [1-9][0-9]{4,} (Tencent QQ number starts from 10000) 31: China Postal Code:[1-9]\d{5}(?! \d) (6 digits in the postal code of China) 32: IP Address: \d+\.\d+\.\d+\.\d+ (useful when extracting IP addresses) 33: IP address:((?:(?:25[0-5]|2[0-4]\\d|[ 01]?\\d?\\d)\\.) {3} (?:25[0-5]|2[0-4]\\d| [01]?\\d?\\d))
|