The js regular expressions you want are here!

1. js regular expression for check digit

1. Numbers: ^[0-9]*$
2. Numbers with n digits: ^\d{n}$
3. Numbers with at least n digits: ^\d{n,}$
4. Numbers with mn digits: ^\d{m,n}$
5. Numbers starting with zero and non-zero: ^(0|[1-9][0-9]*)$
6. Numbers starting with non-zero and up to two decimal places: ^([1-9][0-9]*)+(.[0-9]{1,2})?$
7. Positive or negative numbers with 1-2 decimal places: ^(\-)?\d+(\.\d{1,2})?$
8. Positive numbers, negative numbers, and decimals: ^(\-|\+)?\d+(\.\d+)?$
9. Positive real numbers with two decimal places: ^[0-9]+(.[0-9]{2})?$
10. Positive real numbers with 1 to 3 decimal places: ^[0-9]+(.[0-9]{1,3})?$
11. Non-zero Positive integers: ^[1-9]\d*$ 或 ^([1-9][0-9]*){1,3}$ 或 ^\+?[1-9][0-9]*$
12, non-zero negative integers: ^\-[1-9][]0-9"*$ 或 ^-[1-9]\d*$
13, non-negative integers: ^\d+$ 或 ^[1-9]\d*|0$
14, non-positive integers: ^-[1-9]\d*|0$ 或 ^((-\d+)|(0+))$
15, non-negative floating-point numbers: ^\d+(\.\d+)?$ 或 ^[1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0$
16, non-positive floating-point numbers: ^((-\d+(\.\d+)?)|(0+(\.0+)?))$ 或 ^(-([1-9]\d*\.\d*|0\.\d*[1-9]\d*))|0?\.0+|0$
17, positive floating-point numbers: ^[1-9]\d*\.\d*|0\.\d*[1-9]\d*$ 或 ^(([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 numbers: ^-([1-9]\d*\.\d*|0\.\d*[1-9]\d*)$ 或 ^(-(([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+)?$ 或 ^-?([1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0)$

2. JS regular expression of check character

1. Chinese characters: ^[\u4e00-\u9fa5]{0,}$
2. English and numbers: ^[A-Za-z0-9]+$ 或 ^[A-Za-z0-9]{4,40}$
3. All characters with a length of 3-20: ^.{3,20}$
4. A string consisting of 26 English letters: ^[A-Za-z]+$
5. A string consisting of 26 uppercase English letters: ^[A-Z]+$
6. A string consisting of 26 A string consisting of two lowercase English letters: ^[a-z]+$
7. A string consisting of numbers and 26 English letters: ^[A-Za-z0-9]+$
8. A string consisting of numbers, 26 English letters or underscores: ^\w+$ 或 ^\w{3,20}$
9. Chinese, English, numbers including underscores: ^[\u4E00-\u9FA5A-Za-z0-9_]+$
10 , Chinese, English, numbers but not including underscore and other symbols: ^[\u4E00-\u9FA5A-Za-z0-9]+$ 或 ^[\u4E00-\u9FA5A-Za-z0-9]{2,20}$
11. It is forbidden to enter characters containing ~:[^~\x22]+

Three, special needs js regular expression

1. Email address: ^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$ 另外一个: /^[A-Za-z0-9._%-]+@([A-Za-z0-9-]+\.)+[A-Za-z]{2,4}$/
2. URL domain name: [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]* 或 ^http://([\w-]+\.)+[\w-]+(/[\w-./?%&=]*)?$
4. 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}$another one: /^1[3|4|5|7|8]\d{9}$/
5. Telephone number: ^(\(\d{3,4}-)|\d{3.4}-)?\d{7,8}$
6. Domestic telephone number (0511-4405222, 021-87888822):\d{3}-\d{8}|\d{4}-\d{7}

ID number:
15 or 18-digit ID card:^\d{15}|\d{18}$
15-digit ID card:^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$
18-digit ID card:^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{4}$
7. Short ID number (number, letter x ending):^([0-9]){7,18}(x|X)?$ 或 ^\d{8,18}|[0-9x]{8,18}|[0-9X]{8,18}?$
8. Whether the account number is legal (starting with a letter, allowing 5-16 bytes ,Alphanumeric underline is allowed):^[a-zA-Z][a-zA-Z0-9_]{4,15}$
9. Password (beginning with a letter, the length is between 6~18, and 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, cannot be used Special characters, the length is between 8-10):^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,10}$
11. Date format:^\d{4}-\d{1,2}-\d{1,2}
12, 12 months of the year (01~09 and 1~12):^(0?[1-9]|1[0-2])$

Money input format: *
1. There are four representations of money we can accept: "10000.00" and "10,000.00", and "10000" and "10,000" without "points": ^[1-9][0-9]*$
2. This means that any one of them is not 0 However, this also means that a character "0" is not passed, so we use 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 negative sign at the beginning: ^(0|-?[1-9][0-9]*)$
4. This means a 0 or a possible negative number that 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 to illustrate the possibility Decimal part: ^[0-9]+(.[0-9]+)?$
5. It must be stated that there should be at least 1 digit after the decimal point, so "10." is not passed, but "10" and "10.2" are passed: ^[0-9]+(.[0-9]{2})?$
6. In this way, we stipulate that there must be after the decimal point Two ^[0-9]+(.[0-9]{1,2})?$
digits , if you think it is too harsh, you can do this: 7. This allows the user to write only one decimal place. Now we should consider the comma in the number, we can do this: ^[0-9]{1,3}(,[0-9]{3})*(.[0-9]{1,2})?$
8, 1 to 3 digits, followed by any number A comma + 3 numbers, the comma becomes optional, not necessary: ^([0-9]+|[0-9]{1,3}(,[0-9]{3})*)(.[0-9]{1,2})?$
9. Remarks: This is the final result, don’t forget that "+" can be replaced with "*". If you think an empty string is also acceptable (strange , Why?) Finally, don’t forget to remove the backslash when using the function. The general errors are here.
10. The xml file: ^([a-zA-Z]+-?)+[a-zA-Z0-9]+\\.[x|X][m|M][l|L]$
11. The regular expression of Chinese characters: [\u4e00-\u9fa5]
12. Double-byte characters: [^\x00-\xff](including Chinese characters Inside, it can be used to calculate the length of the string (a double-byte character counts as 2, ASCII character counts as 1))
13. Blank line regular expression: \n\s*\r(can be used to delete blank lines)
14. HTML mark regular expression expression:<(\S*?)[^>]*>.*?</\1>|<.*? />
15. Regular expressions of blank characters at the beginning and end: ^\s*|\s*$或(^\s*)|(\s*$)(can be used to delete blank characters at the beginning and end of a line (including spaces, tabs, form feeds, etc.), very useful expressions)
16. Tencent QQ number: [1-9][0-9]{4,}( Tencent QQ number starts from 10000)
17. Chinese postal code: [1-9]\d{5}(?!\d)(Chinese postal code is 6 digits)
18. IP address: \d+\.\d+\.\d+\.\d+(useful when extracting IP address)
19. Can’t be empty: /\S/
20. Match blank line:^(\s*)\n

You can leave a message and I will make up if it is not complete!

Guess you like

Origin blog.csdn.net/Smell_rookie/article/details/106780211