SoFunction
Updated on 2025-03-10

js commonly used regular expression form verification code

Detailed explanation of regular expression usage

Introduction

Simply put, regular expressions are a powerful tool that can be used for pattern matching and replacement. Its functions are as follows:
Tests a pattern of a string. For example, you can test an input string to see if there is a phone number pattern or a credit card number pattern in the string. This is called data validation.
Replace text. You can use a regular expression in a document to identify a specific text, and then you can delete it all, or replace it with another text.
Extract a substring from the string according to pattern matching. Can be used to find specific text in text or input fields.

Basic syntax

After gaining a preliminary understanding of the functions and functions of regular expressions, let’s take a look at the syntax format of regular expressions in detail.

The form of regular expressions is generally as follows:

/love/The part between the "/" delimiter is the pattern to match in the target object. The user just needs to put the pattern content of the matching object in the "/" delimiter. To enable users to customize pattern content more flexibly, regular expressions provide special "metachars". The so-called metacharacter refers to those special characters with special meaning in regular expressions, which can be used to specify the appearance pattern of their leading characters (that is, characters that are before the metacharacter) in the target object.
The more commonly used metacharacters include: "+", "*", and "?".
The "+" metacharacter specifies that its leading character must appear once or more consecutively in the target object.
The "*" metacharacter specifies that its leading character must appear zero or multiple consecutive times in the target object.
The "?" metacharacter specifies that its leading object must appear zero or once in a row in the target object.

Next, let's take a look at the specific application of regular expression metacharacters.

/fo+/ Because the above regular expression contains the "+" metacharacter, it can match a string such as "fool", "fo" or "football" in the target object that appears one or more letters o in succession after the letter f.
/eg*/Because the above regular expression contains the "*" metacharacter, it means that it can match a string with zero or more letters g in the target object, such as "easy", "ego", or "egg" in the target object, which appears in succession after the letter e.
/Wil?/Because the above regular expression contains the "?" metacharacter, it means that it can match the string of zero or one letter l in the target object, etc., which appears successively after the letter i.

Sometimes I don't know how many characters to match. To be able to adapt to this uncertainty, regular expressions support the concept of qualifiers. These qualifiers can specify how many times a given component of a regular expression must appear before the match can be met.

{n} n is a non-negative integer. Match the n times that are determined. For example, 'o{2}' cannot match 'o' in "Bob", but can match two os in "food".
{n,} n is a non-negative integer. Match at least n times. For example, 'o{2,}' cannot match 'o' in "Bob" but can match all os in "fooooood". 'o{1,}' is equivalent to 'o+'. 'o{0,}' is equivalent to 'o*'.
{n,m} m and n are non-negative integers, where n <= m. Match at least n times and match up to m times. For example, "o{1,3}" will match the first three os in "fooooooood". 'o{0,1}' is equivalent to 'o?'. Please note that there cannot be spaces between commas and two numbers.
In addition to metacharacters, users can also specify exactly how often the pattern appears in the matching object. For example, /jim {2,6}/ The above regular expression stipulates that the character m can appear 2-6 times in the matching object, so the above regular expression can be matched with strings such as jimmy or jimmmmy.

After gaining a preliminary understanding of how to use regular expressions, let's take a look at how to use several other important metacharacters.
\s: used to match a single space character, including tab keys and line breaks;
\S: Used to match all characters except a single space character;
\d: used to match numbers from 0 to 9;
\w: Used to match letters, numbers or underscore characters;
\W: Used to match all characters that do not match \w;
.: Used to match all characters except line breaks.

(Note: We can regard \s and \S and \w and \W as inverse operations)

Next, we will take an example to see how to use the above metacharacter in regular expressions.

/\s+/ The above regular expressions can be used to match one or more space characters in the target object.
/\d000/ If we have a complex financial statement in our hands, we can easily find all payments with a total amount of 1,000 yuan through the above regular expression.
In addition to the metacharacters we have introduced above, regular expressions also have another unique special character, namely, locators. Locators are used to specify where the matching pattern appears in the target object. More commonly used locators include: "^", "$", "\b" and "\B".
"^" locator specifies that the matching pattern must appear at the beginning of the target string
The "$" locator specifies that the matching pattern must appear at the end of the target object
"\b" locator specifies that the matching pattern must appear at one of the two boundaries at the beginning or end of the target string
The "\B" locator specifies that the matching object must be within the two boundaries of the beginning and end of the target string.
That is, the matching object cannot be used as the beginning of the target string or the end of the target string.
Similarly, we can also regard "^" and "$" and "\b" and "\B" as two sets of locators that are inverse operations. For example: /^hell/ Because the above regular expression contains the "^" locator, it can match a string starting with "hell", "hello" or "hellhound" in the target object. /ar$/ Because the above regular expression contains the "$" locator, it can be matched with a string ending in "car", "bar" or "ar" in the target object. /\bbom/ Because the above regular expression pattern starts with the "\b" locator, it can match a string starting with "bomb", or "bom" in the target object. /man\b/ Because the above regular expression pattern ends with the "\b" locator, it can be matched with a string ending with "human", "woman" or "man" in the target object.
In order to facilitate users to set matching patterns more flexibly, regular expressions allow users to specify a certain range in the matching patterns without being limited to specific characters. For example:
/[A-Z]/The above regular expression will match any capital letter in the range A to Z.
/[a-z]/The above regular expression will match any lowercase letter in the range a to z.
/[0-9]/ The above regular expression will match any number in the range from 0 to 9.
/([a-z][A-Z][0-9])+/ The above regular expression will match any string composed of letters and numbers, such as "aB0", etc.

One thing that needs to be reminded here is that you can use "()" in regular expressions to combine strings together. The contents of the "()" symbol must appear in the target object at the same time. Therefore, the above regular expression will not be able to match a string such as "abc" and so on, because the last character in "abc" is a letter rather than a number.
If we want to implement "or" operations similar to programming logic in regular expressions and choose one of multiple different patterns to match, we can use the pipeline character "|". For example: /to|too|2/ The above regular expression will match "to", "too", or "2" in the target object.
There is also a more commonly used operator in regular expressions, namely the negative character "[^]". Unlike the locator "^" we introduced earlier, the negative character "[^]" stipulates that the string specified in the pattern cannot exist in the target object. For example: /[^A-C]/The above string will match any character in the target object except A, B, and C. Generally speaking, when "^" appears in "[]", it is regarded as a negative operator; when "^" is outside "[]", or there is no "[]", it should be regarded as a locator.
Finally, when the user needs to add metacharacters to the pattern of the regular expression and find their matching object, the escape character "\" can be used. For example: /Th\*/ The above regular expression will match "Th*" instead of "The" in the target object.

After constructing a regular expression, you can evaluate the value like a mathematical expression, that is, you can evaluate it from left to right and in a priority order. The priority is as follows:

1.\ escape character
2.(), (?:), (?=), [] brackets and square brackets
3.*, +, ?, {n}, {n,}, {n,m} qualifiers
4.^, $, \anymetacharacter Position and Order
5.|"OR" operation

Examples of usage

There is a powerful RegExp() object in JavaScript 1.2 that can be used to match regular expressions. The test() method can check whether the target object contains a matching pattern and return true or false accordingly.
We can use JavaScript to write the following script to verify the validity of the email address entered by the user.
Regular expression object
This object contains regular expression patterns and flags indicating how the patterns are applied.
Syntax 1 re = /pattern/[flags]
Syntax 2 re = new RegExp("pattern",["flags"])
parameter
re
Required option. The name of the variable to be assigned to the regular expression pattern.
Pattern
Required option. Regular expression pattern to use. If syntax 1 is used, separate the mode with the "/" character. If syntax 2 is used, enclose the pattern in quotes.
Flags
Optional. If using syntax 2, enclose flags in quotes. Logo can be used in combination, and those available are:
g (Full text to find all patterns that appear)
i (Ignore case)
m (multiple line search)

Example

The following example creates an object (re) containing regular expression patterns and related flags to demonstrate how to use regular expression objects. In this example, the resulted regular expression object is used in the match method:

Copy the codeThe code is as follows:

function MatchDemo()
{
var r, re; // Declare variables.
var s = "The rain in Spain falls mainly in the plain";
re = new RegExp("ain","g"); // Create a regular expression object.
r = (re); // Find a match in the string s.
return(r);
}
The following are the specific uses:

Method 1:
var re=/regular expression/;
($("txtid").val())

Method 2:
$("txtid").(/regular expression/);

Regular expressions come in many different styles. The following table is a complete list of metacharacters and their behavior in the context of regular expressions in PCRE:

character describe
\ Mark the next character as a special character, or an primitive character, or a backward reference, or an octal escape character. For example, "n" matches the character "n". "\n" matches a newline character. The sequence "\\" matches "\" and "\(" matches "(".
^ Matches the start position of the input string. If the Multiline property of the RegExp object is set, ^ also matches the position after "\n" or "\r".
$ Matches the end position of the input string. If the Multiline property of the RegExp object is set, $ also matches the position before "\n" or "\r".
* Matches the previous subexpression zero or multiple times. For example, zo* can match "z" and "zoo". *Equivalent to {0,}.
+ Matches the previous subexpression once or more times. For example, "zo+" can match "zo" and "zoo", but cannot match "z". + is equivalent to {1,}.
? Matches the previous subexpression zero or once. For example, "do(es)?" can match "do" in "do" or "does". ?Equivalent to {0,1}.
{n} n is a non-negative integer. Match the n times that are determined. For example, "o{2}" cannot match "o" in "Bob", but can match two os in "food".
{n,} n is a non-negative integer. Match at least n times. For example, "o{2,}" cannot match "o" in "Bob", but can match all os in "fooooood". "o{1,}" is equivalent to "o+". "o{0,}" is equivalent to "o*".
{n,m} Both m and n are non-negative integers, where n<=m. Match at least n times and match up to m times. For example, "o{1,3}" will match the first three os in "foooooood". "o{0,1}" is equivalent to "o?". Please note that there cannot be spaces between commas and two numbers.
? When the character is immediately followed by any other restriction character (*,+,?,{n},{n,},{n,m}), the matching pattern is non-greedy. The non-greedy pattern matches as few strings as possible, while the default greedy pattern matches as many strings as possible. For example, for the string "oooo", "o+?" will match a single "o", and "o+" will match all "o".
. Match any single character except "\n". To match any character including "\n", use a pattern like "[.\n]".
(pattern) Match pattern and get this match. The obtained matches can be obtained from the generated Matches collection, using the SubMatches collection in VBScript, and using the $0…$9 attribute in JScript. To match parentheses characters, use "\(" or "\)".
(?:pattern) Match pattern but do not get the matching result, that is, this is a non-get match and is not stored for future use. This is useful when using the character "(|)" to combine various parts of a pattern. For example, "industr(?:y|ies)" is an expression that is simpler than "industry|industries".
(?=pattern) Forward pre-check, match the lookup string at the beginning of any string matching pattern. This is a non-get match, that is, the match does not need to be retrieved for later use. For example, "Windows(?=95|98|NT|2000)" can match "Windows" in "Windows2000", but cannot match "Windows" in "Windows3.1". Pre-checking does not consume characters, that is, after a match occurs, the next match's search begins immediately after the last match, rather than after the characters containing the pre-checking.
(?!pattern) Negative pre-check, matching the lookup string at the beginning of any string that does not match the pattern. This is a non-get match, that is, the match does not need to be retrieved for later use. For example, "Windows(?!95|98|NT|2000)" can match "Windows" in "Windows3.1", but cannot match "Windows" in "Windows2000". Pre-checking does not consume characters, that is, after a match occurs, the next match search begins immediately after the last match, rather than after the characters containing the pre-checking
x|y Match x or y. For example, "z|food" can match "z" or "food". "(z|f)ood" matches "zood" or "food".
[xyz] Character collection. Match any character contained. For example, "[abc]" can match "a" in "plain".
[^xyz] A collection of negative values ​​characters. Match any characters not included. For example, "[^abc]" can match "p" in "plain".
[a-z] Character range. Match any character in the specified range. For example, "[a-z]" can match any lowercase alphabetical characters in the range "a" to "z".
[^a-z] Negative value character range. Match any arbitrary characters that are not within the specified range. For example, "[^a-z]" can match any arbitrary character that is not in the range of "a" to "z".
\b Match a word boundary, which means the position between the word and space. For example, "er\b" can match "er" in "never", but cannot match "er" in "verb".
\B Match non-word boundaries. "er\B" can match "er" in "verb", but cannot match "er" in "never".
\cx Matches the control characters specified by x. For example, \cM matches a Control-M or carriage return character. The value of x must be one of A-Z or a-z. Otherwise, treat c as an original "c" character.
\d Match a numeric character. Equivalent to [0-9].
\D Match a non-numeric character. Equivalent to [^0-9].
\f Match a page break. Equivalent to \x0c and \cL.
\n Match a newline character. Equivalent to \x0a and \cJ.
\r Match a carriage return character. Equivalent to \x0d and \cM.
\s Match any whitespace characters, including spaces, tabs, page breaks, etc. Equivalent to [\f\n\r\t\v].
\S Match any non-whitespace characters. Equivalent to [^\f\n\r\t\v].
\t Match a tab character. Equivalent to \x09 and \cI.
\v Match a vertical tab. Equivalent to \x0b and \cK.
\w Match any word character that includes an underscore. Equivalent to "[A-Za-z0-9_]".
\W Match any non-word characters. Equivalent to "[^A-Za-z0-9_]".
\xn Match n, where n is a hexadecimal escape value. The hexadecimal escape value must be the length of two numbers that are determined. For example, "\x41" matches "A". "\x041" is equivalent to "\x04&1". ASCII encoding can be used in regular expressions. .
\num Match num, where num is a positive integer. Reference to the obtained match. For example, "(.)\1" matches two consecutive identical characters.
\n Identifies an octal escape value or a backward reference. If \n has at least n obtained subexpressions before, n is a backward reference. Otherwise, if n is an octal number (0-7), n is an octal escape value.
\nm Identifies an octal escape value or a backward reference. If there are at least nm obtaining subexpressions before \nm, nm is a backward reference. If there are at least n retrieves before \nm, n is a backward reference followed by the literal m. If none of the previous conditions are satisfied, if n and m are octal numbers (0-7), then \nm will match the octal escape value nm.
\nml If n is an octal number (0-3), and both m and l are octal numbers (0-7), the octal escape value nml is matched.
\un Match n, where n is a Unicode character represented by four hexadecimal numbers. For example, \u00A9 matches the copyright symbol (?).


Attached:

Set of regular expressions for validating numbers (reprinted)
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+)?

The following is the specific function writing method. If you don’t know, please refer to it.
Copy the codeThe code is as follows:

function check()
{
var bb = ("txt_id").value;//txt_id is the ID of the text box
alert(ismobile(bb));//ismobile represents any of the following function names
}
HTML code:
<input type="text" name="textfield" />
<input type="submit" name="Submit" value="submit" onclick="check()" />
**************************/
// Determine whether the input is a string composed of 0-9 / A-Z / a-z
function isalphanumber(str)
{
var result=(/^[a-zA-Z0-9]+$/);
if(result==null) return false;
return true;
}

// Determine whether the input is a number-(number contains decimals)-
function isnumber(str)
{
return !isNaN(str);
}


// Determine whether the input is an integer
function isint(str)
{
var result=(/^(-|\+)?\d+$/);
if(result==null) return false;
return true;
}


// Determine whether the input is valid long date format - "YYYY-MM-DD HH:MM:SS" || "YYYY/MM/DD HH:MM:SS"
function isdatetime(str)
{
var result=(/^(\d{4})(-|\/)(\d{1,2})\2(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/);
if(result==null) return false;
var d= new Date(result[1], result[3]-1, result[4], result[5], result[6], result[7]);
return (()==result[1]&&(()+1)==result[3]&&()==result[4]&&()==result[5]&&()==result[6]&&()==result[7]);
}


// Check whether it is YYYY-MM-DD || YYYY/MM/DD date format
function isdate(str){
var result=(/^(\d{4})(-|\/)(\d{1,2})\2(\d{1,2})$/);
if(result==null) return false;
var d=new Date(result[1], result[3]-1, result[4]);
return (()==result[1] && ()+1==result[3] && ()==result[4]);
}


// Determine whether the input is valid for email
function isemail(str)
{
var result=(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/);
if(result==null) return false;
return true;
}


// Remove the spaces at the beginning and end of the string
function trim(str){
return (/(^\s*)|(\s*$)/g, "");
}


// Return the actual length of the string, one Chinese character calculates 2 lengths
function strlen(str){
return (/[^\x00-\xff]/g, "**").length;
}


//Match the Chinese postal code (6 digits)
function ispostcode(str)
{
var result=(/[1-9]\d{5}(?!\d)/);
if(result==null) return false;
return true;
}
//Match domestic phone number (0511-4405222 or 021-87888822)
function istell(str)
{
var result=(/\d{3}-\d{8}|\d{4}-\d{7}/);
if(result==null) return false;
return true;
}

//Check whether it is an integer (0-10000)
function isint1(str)
{
var result=(/^[0-9]$|^([1-9])([0-9]){0,3}$|^10000$/);
if(result==null) return false;
return true;
}


//Match Tencent QQ number
function isqq(str)
{
var result=(/[1-9][0-9]{4,}/);
if(result==null) return false;
return true;
}


//Match ID card (15 or 18)
function isidcard(str)
{
var result=(/\d{15}|\d{18}/);
if(result==null) return false;
return true;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//Check whether the text is empty
function checknull(field,sval)
{
if ( =="")
{
alert("Please fill in" + sval + "!");
();
return false;
}
return true;
}


//Mask input characters
/***********************
Calling method:
Add onkeypress="return checkChar()" to the text box
*************************/
function checkChar()
{
var keycode = ;
if(!(keycode>=48&&keycode<=57))
{
return false;
}
}


/***************************************************************************************************************************
China Telephone Number Verification
Matching forms are: 0511-4405222 or 021-87888822 or 021-44055520-555 or (0511)4405222
Regular expression "((d{3,4})|d{3,4}-)?d{7,8}(-d{3})*"

China Postal Code Verification
Matching form is as follows: 215421
Regular expression "d{6}"

Email Verification
Matching form is: justali@
Regular expression "w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*"

Identity card verification
Matching form: 15-bit or 18-bit ID card
Regular expression "d{18}|d{15}"

Commonly used digital verification
Regular expressions
"d{n}" n is the specified length
"d{n,m}" length range from n to m

Illegal character verification
Match illegal characters such as: < > & / ' |
Regular expression [^<>&/|'\]+

Date verification
Matching form is as follows: 20030718,030718
Range: 1900--2099
Regular expression((((19){1}|(20){1})d{2})|d{2})[01]{1}d{1}[0-3]{1}d{1}



Regular expression matching Chinese characters: [\u4e00-\u9fa5]
Comment: Matching Chinese is really a headache, it's easy to do with this expression

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

Regular expression matching blank lines:\n\s*\r
Comment: Can be used to delete blank lines

Regular expression matching HTML tags: < (\S*?)[^>]*>.*?|< .*? />
Comment: 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 whitespace characters: ^\s*|\s*$
Comment: 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 email address: \w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*
Comment: It is very practical when verifying the form

Regular expression matching URL: [a-zA-z]+://[^\s]*
Comment: The functions of the version circulating online are very limited, and the above can basically meet the needs

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}$
Comment: It is very practical when verifying the form

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

Match Tencent QQ number: [1-9][0-9]{4,}
Comment: Tencent QQ number starts at 10,000

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

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

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

The IP address in the extract information:
(\d+)\.(\d+)\.(\d+)\.(\d+)

Extract Chinese mobile phone numbers from the information:
(86)*0*13\d{9}

Chinese landline phone number extracted from the information:
(\(\d{3,4}\)|\d{3,4}-|\s)?\d{8}

Extract Chinese phone numbers from the information (including mobile and landline phones):
(\(\d{3,4}\)|\d{3,4}-|\s)?\d{7,14}

Chinese postal codes in the extract information:
[1-9]{1}(\d+){5}

Extract the Chinese ID number in the information:
\d{18}|\d{15}

Extract integers in the information:
\d+

Extract floating point numbers (i.e. decimals) from the information:
(-?\d*)\.?\d+

Extract any number in the information:
(-?\d*)(\.\d+)?

Extract Chinese strings from the information:
[\u4e00-\u9fa5]*

Extract the double-byte string (Chinese characters):
[^\x00-\xff]*

Extract the English string from the information:
\w*
Extract the network link in the information:
(h|H)(r|R)(e|E)(f|F) *= *('|")?(\w|\\|\/|\.)+('|"| *|>)?

Email address in the extract message:
\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*

Image links in the extract information:
(s|S)(r|R)(c|C) *= *('|")?(\w|\\|\/|\.)+('|"| *|>)?


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)
Comment: 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
Comment: Some of the most basic and most commonly used expressions



////////////////////////////// The first 4 lines of the program are used to protect the js code from being downloaded
// ///////////////////////////////////////////////////////////////////////////////////
//Non-null verification function NotNull (str) { return (str!=""); }
//Email address verification
function checkEmail (str) {
//The regular expression of email address isEmail1=/^\w+([\.\-]\w+)*\@\w+([\.\-]\w+)*\.\w+$/;
//The regular expression of email address isEmail2=/^.*@[^_]*$/;
//Verify the email address and return the result return ((str)&&(str));
} //ID card verification function checkIDCard (str) {
//Identity card regular expression (15 bits)
isIDCard1=/^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$/;
//Identity card regular expression (18 bits) isIDCard2=/^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{4}$/;
//Verify the ID card and return the result return ((str)||(str)); }
//IP verification function checkIP (str)
{ //IP regular expression IP='(25[0-5]|2[0-4]\\d|1\\d\\d|\\d\\d|\\d)';
IPdot=IP+'\\.'; isIPaddress=new RegExp('^'+IPdot+IPdot+IPdot+IP+'$');
//Verify the IP and return the result return ((str)); }
//Homepage (website) verification function checkHomepage (str) {
//Homepage regular expression //isHomepage=/^\w+([\.\-]\w)*$/; isHomepage=/^\w+(\.\w+)+\.\w+$/;
//Verify the home page and return the result return ((str)); }
//Is the number function isNum (str) { //isNumber=/^([1-9]\d*(\.\d+)?)|(\d+(\.\d+))$/; isNumber=/^\d+(\.\d+)?$/;
//Verify and return the result return ((str)); }
//Is integer function isInt (str) { isInteger=/^\d+$/;
//Verify and return the result return ((str)); }
//Is the letter function isChar (str) { isCharacter=/^[A-Za-z]+$/;
//Verify and return the result return ((str)); }
/////////////////////////////////////////////////////////////////////////////
function checkBoolean(bv,i,w) { if(bv==false) { try{();}catch(e){} alert(w); return false; } return true }
////////////////////////////////////////////////////////////////////////////
function checkElement_selected(item,alert_str) { if(=="select-one")return checkElement_NotNull(item,alert_str); if(alert_str.length==0)alert_str=+" is required!"; rt=false; if(>0) { for(i=0;i<;i++){rt=rt||item[i].checked;} } else { rt= } return checkBoolean(rt,item[0],alert_str); return true; } //
Not empty function checkElement_NotNull(a,alert_str,g) { v=; w=alert_str; if(alert_str.length==0)w=+"Can not be empty!"; return(checkValue_NotNull(v,a,w,g)); } function checkValue_NotNull(v,i,w,g) { if(g!="NOT_TRIM")v=(/(^\s*)|(\s*$)/g, ""); bv=NotNull(v); return(checkBoolean(bv,i,w)); }
// Legal mailbox function checkElement_IsEmail(a,alert_str,g) { v=; w=alert_str; if(alert_str.length==0)w=+"Can not be empty!"; return(checkValue_IsEmail(v,a,w,g)); }
function checkValue_IsEmail(v,i,w,g) { if(g!="NOT_TRIM")v=(/(^\s*)|(\s*$)/g, ""); bv=checkEmail(v); return(checkBoolean(bv,i,w)); } // Legal ID card function checkElement_IsIDCard(a,alert_str,g) { v=; w=alert_str; if(alert_str.length==0)w=+"Cannot be empty!"; return(checkValue_IsIDCard(v,a,w,g)); }
function checkValue_IsIDCard(v,i,w,g) { if(g!="NOT_TRIM")v=(/(^\s*)|(\s*$)/g, ""); bv=checkIDCard(v); return(checkBoolean(bv,i,w)); } // Legal IP function checkElement_IsIP(a,alert_str,g) { v=; w=alert_str; if(alert_str.length==0)w=+"Cannot be empty!"; return(checkValue_IsIP(v,a,w,g)); } function checkValue_IsIP(v,i,w,g) { if(g!="NOT_TRIM")v=(/(^\s*)|(\s*$)/g, ""); bv=checkIP(v); return(checkBoolean(bv,i,w)); }
// Verify the number function checkElement_IsNum(a,alert_str,g) { v=; w=alert_str; if(alert_str.length==0)w=+"Can not be empty!"; return(checkValue_IsNum(v,a,w,g)); } function checkValue_IsNum(v,i,w,g) { if(g!="NOT_TRIM")v=(/(^\s*)|(\s*$)/g, ""); bv=isNum(v); return(checkBoolean(bv,i,w)); }
// Verify integer function checkElement_IsInt(a,alert_str,g) { v=; w=alert_str; if(alert_str.length==0)w=+"Can not be empty!"; return(checkValue_IsInt(v,a,w,g)); } function checkValue_IsInt(v,i,w,g) { if(g!="NOT_TRIM")v=(/(^\s*)|(\s*$)/g, ""); bv=isInt(v); return(checkBoolean(bv,i,w)); } // Verify letter function checkElement_IsChar(a,alert_str,g) { v=; w=alert_str; if(alert_str.length==0)w=+"Can not be empty!"; return(checkValue_IsChar(v,a,w,g)); } function checkValue_IsChar(v,i,w,g) { if(g!="NOT_TRIM")v=(/(^\s*)|(\s*$)/g, ""); bv=isChar(v); return(checkBoolean(bv,i,w)); }
// Legal homepage function checkElement_IsHomepage(a,alert_str,g) { v=; w=alert_str; if(alert_str.length==0)w=+"Can not be empty!"; return(checkValue_IsHomepage(v,a,w,g)); } function checkValue_IsHomepage(v,i,w,g) { if(g!="NOT_TRIM")v=(/(^\s*)|(\s*$)/g, ""); bv=checkHomepage(v); return(checkBoolean(bv,i,w)); }