Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the JavaScript regular expressions?

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces what JavaScript regular expressions have, which can be used for reference by interested friends. I hope you can learn a lot after reading this article.

Verification number: ^ [0-9] * $

Verify the n-digit number: ^\ d {n} $

Verify at least n digits: ^\ d {n,} $

Verify the number of mmurn digits: ^\ d {mcentine n} $

Verify zero and non-zero numbers: ^ (0 | [1-9] [0-9] *) $

Verify the positive real number with two decimal places: ^ [0-9] + (. [0-9] {2})? $

Verify a positive real number with 1-3 decimal places: ^ [0-9] + (. [0-9] {1Jue 3})? $

Verify non-zero positive integers: ^\ +? [1-9] [0-9] * $

Verify non-zero negative integers: ^\-[1-9] [0-9] * $

Verify that non-negative integers (positive integers + 0) ^\ dflowers $

Verify non-positive integer (negative integer + 0) ^ ((-\ d +) | (0 +)) $

Verify a character of length 3: ^. {3} $

Verify the 26-letter string: ^ [A-Za-z] + $

Verify the string of 26 uppercase letters: ^ [Amurz] + $

Verify the string of 26 lowercase letters: ^ [amurz] + $

Verify the string consisting of numbers and 26 letters: ^ [A-Za-z0-9] + $

Verify a string consisting of numbers, 26 letters, or an underscore: ^\ wicked $

Verify the user password: ^ [a-zA-Z]\ w {5pm 17} $is in the correct format: begins with a letter, is between 6 and 18 in length, and can only contain characters, numbers, and underscores.

Verify whether it contains characters such as ^% &',; =? $\ ": [^% &',; =? $\ x22] +

Verify Chinese characters: ^ [\ u4e00 -\ u9fa5], {0,} $

Verify the Email address: ^\ w + [- +.]\ w +) * @\ w + ([-.]\ w +) *.\ w + ([-.]\ w +) * $

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

Verify the phone number: ^ (\ (\ d {3pr 4}\) |\ d {3pr 4} -)?\ d {7J 8} $:-- the correct format is: XXXX-XXXXXXX,XXXX-XXXXXXXX,XXX-XXXXXXX,XXX-

XXXXXXXX,XXXXXXX,XXXXXXXX .

Verify ID number (15 or 18 digits): ^\ d {15} |\ d {} 18 $

Verify that the 12 months of the year: ^ (0? [1-9] | 1 [0-2]) $is in the correct format: "01"-"09" and "1"12"

Verify the 31 days of a month: ^ ((0? [1-9]) | (1 | 2) [0-9]) | 30 | 31) the correct format is: 01, 09 and 1, 31.

Integer: ^ -?\ dbath $

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 has not been tested, please verify and use

1. You can only enter numbers and English:

two。 You can only enter numbers:

3. You can only enter full-width:

4. Those who can only enter Chinese characters:

5. Email address Verification:

Var regu = "^ (([0-9a-zA-Z] +) | ([0-9a-zA-Z] + [_ .0-9akozAmurz Z -] * [0-9a-zA-Z] +) @ ([a-zA-Z0-9 -] + [a-zA-Z] {2} | net | NET | com | gov | mil | MIL | ORG | edu | EDU | int | INT) $" var re = new RegExp (regu); if (s.search (re)! =-1) {return true } else {window.alert ("Please enter a valid E-mail address!") Return false;}

6. ID card:

"^\ d {17} (\\ d | x) $"

7.17 regular expressions

"^\\ integer $" / / non-negative integer (positive integer + 0)

"^ [0-9] * [1-9] [0-9] * $" / / positive integer

"^ ((-\\ d+) | (0 +) $" / / non-positive integer (negative integer + 0)

"^-[0-9] * [1-9] [0-9] * $" / / negative integer

"^ -?\\ During $" / / Integer

"^\\ d + (\\.\\ d +)? $" / / non-negative floating point number (positive floating point number + 0)

"^ (([0-9] +. [0-9] * [1-9] [0-9] *) | ([0-9] * [1-9] [0-9] *. [0-9] +) | ([0-9] * [1-9] [0-9] *)) $" / / positive floating point number

"^ (-\\ d + (\\.\\ d +)?) | (0 + (\\ .0 +)) $" / / non-positive floating point number (negative floating point number + 0)

"^ (- (([0-9] +\. [0-9] * [1-9] [0-9] *) | ([0-9] * [1-9] [0-9] *. [0-9] +) | ([0-9] * [1-9] [0-9] *)) $" / / negative floating point number

"^ (-?\\ d +) (\.\\ d +)? $" / / floating point number

"^ [A-Za-z] + $" / / A string of 26 letters

"^ [Amurz] + $" / / A string of 26 English letters in uppercase

A string of 26 lowercase letters consisting of "^ [amurz] + $" / /

"^ [A-Za-z0-9] + $" / / A string of numbers and 26 letters

A string of numbers, 26 letters, or underscores.

"^ [\\ w -] + (\\ .[\\ w -] +) * @ [\\ w -] + (\\ .[\\ w -] +) + $" / / email address

"^ [a-zA-z] +: / / (\\ w+ (-\\ w+) *) (\. (\\ w+ (-\\ w+) *)) * (\\?\ S*)? $" / / url

=

1. Cancel the dotted wireframe when the button is pressed

Add an attribute value of hideFocus or HideFocus=true to input

two。 Read-only text box content

Add attribute value readonly to input

3. Prevent backward emptying of TEXT documents (style content can be used as a class reference)

The 4.ENTER key moves the cursor to the next input box

7. Can only be numbers (no flashing)

8. You can only enter English and numbers (flashing)

9. Shielded input method

10. You can only enter numbers, decimal points, minus (-) characters (no flashing)

11. You can only enter two decimal places and three decimal places (flashing)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report