SoFunction
Updated on 2025-02-28

JS regular expression validation numbers (very full)

Regular expressions describe a pattern of string matching, which can be used to check whether a string contains a certain substring, replace the matching substring, or take out a substring that meets a certain condition from a string, etc.

Let's look at the js code first, as shown below:

<script type="text/javascript">
function SubmitCk() {
var reg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
if (!($("#txtEmail").val())) {
alert("Please enter the correct email address")
return false;
}
}
</script>

Set of regular expressions for validating numbers

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 the email address: /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/

Verify InternetURL: ^http://([\w-]+\.)+[\w-]+(/[\w-./?%&=]*)?$ ; ^[a-zA-z]+://(w+(-w+)*)(.(w+(-w+)*))*(?S*)?$

Verification phone number: ^(\d3,4|\d{3,4}-)?\d{7,8}$:--The correct format is: XXXX-XXXXXXX, XXXX-XXXXXXXXXXXX, XXX-XXXXXXXXXXXXXXX, XXX-

XXXXXXXX,XXXXXXX,XXXXXXXX。

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+)?$

The above is the regular expression of JS verification numbers introduced to you by the editor. 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!