SoFunction
Updated on 2025-04-09

Detailed explanation of form verification method page 2/2


Regular expression matching Chinese characters: [\u4e00-\u9fa5]

Match double-byte characters (including Chinese characters): [^\x00-\xff]
Note: It can be used to calculate the length of a string (one double-byte character length meter 2, ASCII character meter 1)

Regular expression matching blank lines:\n\s*\r
Note: It can be used to delete blank lines

Regular expression matching HTML tags: <(\S*?)[^>]*>.*?</\1>|<.*? />
Note: The version circulating online is too bad, and the above one can only match the part, and it is still powerless to use complex nested markers.

Regular expression matching the beginning and end blank characters: ^\s*|\s*$
Note: It can be used to delete whitespace characters at the beginning and end of the line (including spaces, tabs, page breaks, etc.), a very useful expression

Regular expression matching the email address: \w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*

Regular expression matching URL: [a-zA-z]+://[^\s]*

Match whether the account is legal (beginning with letters, 5-16 bytes allowed, alphanumeric underscores allowed): ^[a-zA-Z][a-zA-Z0-9_]{4,15}$

Match domestic phone number: \d{3}-\d{8}|\d{4}-\d{7}
Note: Matching forms are as follows: 0511-4405222 or 021-87888822

Match Tencent QQ number: [1-9][0-9]{4,}
Note: Tencent QQ number starts at 10000

Match the Chinese postal code: [1-9]\d{5}(?!\d)
Note: China's postal code is 6 digits

Match ID card: \d{15}|\d{18}
Note: China's ID card is 15 or 18 digits

Match IP address: \d+\.\d+\.\d+\.\d+
Note: It is useful when extracting IP addresses

Match specific numbers:
^[1-9]\d*$  //Match positive integers
^-[1-9]\d*$ //Match negative integers
^-?[1-9]\d*$ //Match integers
^[1-9]\d*|0$ //Match non-negative integers (positive integer + 0)
^-[1-9]\d*|0$ //Match non-positive integers (negative integer + 0)
^[1-9]\d*\.\d*|0\.\d*[1-9]\d*$ //Match positive floating point number
^-([1-9]\d*\.\d*|0\.\d*[1-9]\d*)$ //Match negative floating point numbers
^-?([1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0)$ //Match floating point numbers
^[1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0$ //Match non-negative floating point numbers (positive floating point numbers + 0)
^(-([1-9]\d*\.\d*|0\.\d*[1-9]\d*))|0?\.0+|0$//Match non-positive floating point numbers (negative floating point numbers + 0)
Note: It is useful when processing large amounts of data, please pay attention to corrections when applying it in detail.

Match a specific string:
^[A-Za-z]+$//Match a string composed of 26 English letters
^[A-Z]+$//Match a string composed of 26 English letters capitalizations
^[a-z]+$//Match a string composed of 26 English letters lowercase
^[A-Za-z0-9]+$//Match a string composed of numbers and 26 English letters
^\w+$//Match a string composed of numbers, 26 English letters or underscores