SoFunction
Updated on 2025-03-03

Commonly used regular expression examples to facilitate form verification


Verification number: ^[0-9]*$
Verify n-bit number: ^\d{n}$
Verify at least n digits: ^\d{n,}$
Verify the number of m-n bits: ^\d{m,n}$
Verify numbers beginning with zero and non-zero: ^(0|[1-9][0-9]*)$
Verify that there are two decimal places: ^[0-9]+(.[0-9]{2})?$
Verify that positive real numbers with 1-3 decimal places: ^[0-9]+(.[0-9]{1,3})?$
Verify non-zero positive integer: ^\+?[1-9][0-9]*$
Verify non-zero negative integer: ^\-[1-9][0-9]*$
Verify non-negative integers (positive integer + 0) ^\d+$
Verify non-positive integers (negative integer + 0) ^((-\d+)|(0+))$
Verify characters with length 3: ^.{3}$
Verify a string composed of 26 English letters: ^[A-Za-z]+$
Verify a string composed of 26 capital English letters: ^[A-Z]+$
Verify a string composed of 26 lowercase English letters: ^[a-z]+$
Verify a string composed of numbers and 26 English letters: ^[A-Za-z0-9]+$
Verify a string composed of numbers, 26 English letters or underscores: ^\w+$
Verify user password:^[a-zA-Z]\w{5,17}$ The correct format is: start with a letter, length between 6-18, and can only contain characters, numbers and underscores.
Verify that it contains characters such as ^%&',;=?$\": [^%&',;=?$\x22]+
Verify Chinese characters: ^[\u4e00-\u9fa5],{0,}$
Verify email address: ^\w+[-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$
Verify InternetURL: ^http://([\w-]+\.)+[\w-]+(/[\w-./?%&=]*)?$ ; ^[a-zA-z]+://(w+(-w+)*)(.(w+(-w+)*))*(?S*)?$
Verification phone number: ^(\(\d{3,4}\)|\d{3,4}-)?\d{7,8}$:--The correct format is: XXXX-XXXXXXX, XXXX-XXXXXXXX, XXX-XXXXXXXXX, XXXXXXXXXXX, XXXXXXXXXXXX.
Verify ID number (15 or 18 digits): ^\d{15}|\d{}18$
Verify 12 months of one year: ^(0?[1-9]|1[0-2])$ The correct format is: "01"-"09" and "1" and "12"
Verify 31 days of one month: ^((0?[1-9])|((1|2)[0-9])|30|31)$ The correct formats are: 01, 09 and 1, 31.
Integer: ^-?\d+$
Non-negative floating point number (positive floating point number + 0): ^\d+(\.\d+)?$
Positive floating point number ^(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*))$
Non-positive floating point number (negative floating point number + 0) ^((-\d+(\.\d+)?)|(0+(\.0+)?))$
Negative floating point number ^(-((([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+)?$
IP address: (\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])