亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Home Web Front-end JS Tutorial 15 commonly used js regular expressions

15 commonly used js regular expressions

Jun 16, 2017 am 10:24 AM
js regular expression password username

這篇文章給大家收集整理了用戶名和密碼等15個常用的js正則表達式,需要的朋友參考下吧

收集整理了15個常用的javaScript正則表達式,其中包括用戶名、密碼強度、整數、數字、電子郵件地址(Email)、手機號碼、身份證號、URL地址、 IPv4地址、 十六進制顏色、 日期、 QQ號碼、 微信號、車牌號、中文正則。表單驗證處理必備。

1 用戶名正則


//用戶名正則,4到16位(字母,數字,下劃線,減號)
var uPattern = /^[a-zA-Z0-9_-]{4,16}$/;
//輸出 true
console.log(uPattern.test("iFat3"));

2 密碼強度正則


//密碼強度正則,最少6位,包括至少1個大寫字母,1個小寫字母,1個數字,1個特殊字符
var pPattern = /^.*(?=.{6,})(?=.*\d)(?=.*[A-Z])(?=.*[a-z])(?=.*[!@#$%^&*? ]).*$/;
//輸出 true
console.log("=="+pPattern.test("iFat3#"));

3 整數正則


//正整數正則
var posPattern = /^\d+$/;
//負整數正則
var negPattern = /^-\d+$/;
//整數正則
var intPattern = /^-?\d+$/;
//輸出 true
console.log(posPattern.test("42"));
//輸出 true
console.log(negPattern.test("-42"));
//輸出 true
console.log(intPattern.test("-42"));

4 數字正則

可以是整數也可以是浮點數


//正數正則
var posPattern = /^\d*\.?\d+$/;
//負數正則
var negPattern = /^-\d*\.?\d+$/;
//數字正則
var numPattern = /^-?\d*\.?\d+$/;
console.log(posPattern.test("42.2"));
console.log(negPattern.test("-42.2"));
console.log(numPattern.test("-42.2"));

5 Email正則


//Email正則
var ePattern = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
//輸出 true
console.log(ePattern.test(65974040@qq.com));

6 手機號碼正則


//手機號正則
var mPattern = /^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(18[0,5-9]))\d{8}$/;
//輸出 true
console.log(mPattern.test("18600000000"));

7 身份證號正則


//身份證號(18位)正則
var cP = /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;
//輸出 true
console.log(cP.test("11010519880605371X"));

8 URL正則


//身份證號(18位)正則
var cP = /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;
//輸出 true
console.log(cP.test("11010519880605371X"));

9 IPv4地址正則


//ipv4地址正則
var ipP = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
//輸出 true
console.log(ipP.test("115.28.47.26"));

10 十六進制顏色正則


//RGB Hex顏色正則
var cPattern = /^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/;
//輸出 true
console.log(cPattern.test("#b8b8b8"));

11 日期正則


//日期正則,簡單判定,未做月份及日期的判定
var dP1 = /^\d{4}(\-)\d{1,2}\1\d{1,2}$/;
//輸出 true
console.log(dP1.test("2017-05-11"));
//輸出 true
console.log(dP1.test("2017-15-11"));
//日期正則,復雜判定
var dP2 = /^(?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)$/;
//輸出 true
console.log(dP2.test("2017-02-11"));
//輸出 false
console.log(dP2.test("2017-15-11"));
//輸出 false
console.log(dP2.test("2017-02-29"));

12 QQ號碼正則


//QQ號正則,5至11位
var qqPattern = /^[1-9][0-9]{4,10}$/;
//輸出 true
console.log(qqPattern.test("65974040"));

13 微信號正則


//微信號正則,6至20位,以字母開頭,字母,數字,減號,下劃線
var wxPattern = /^[a-zA-Z]([-_a-zA-Z0-9]{5,19})+$/;
//輸出 true
console.log(wxPattern.test("RuilongMao"));

14 車牌號正則


//車牌號正則
var cPattern = /^[京津滬渝冀豫云遼黑湘皖魯新蘇浙贛鄂桂甘晉蒙陜吉閩貴粵青藏川寧瓊使領A-Z]{1}[A-Z]{1}[A-Z0-9]{4}[A-Z0-9掛學警港澳]{1}$/;
//輸出 true
console.log(cPattern.test("京K39006"));

15 包含中文正則


//包含中文正則
var cnPattern = /[\u4E00-\u9FA5]/;
//輸出 true
console.log(cnPattern.test("42度"));

The above is the detailed content of 15 commonly used js regular expressions. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1488
72
How to solve the problem that Windows 11 prompts you to enter the administrator username and password to continue? How to solve the problem that Windows 11 prompts you to enter the administrator username and password to continue? Apr 11, 2024 am 09:10 AM

When using Win11 system, sometimes you will encounter a prompt that requires you to enter the administrator username and password. This article will discuss how to deal with this situation. Method 1: 1. Click [Windows Logo], then press [Shift+Restart] to enter safe mode; or enter safe mode this way: click the Start menu and select Settings. Select "Update and Security"; select "Restart Now" in "Recovery"; after restarting and entering the options, select - Troubleshoot - Advanced Options - Startup Settings -&mdash

Incorrect password, beware BitLocker warning Incorrect password, beware BitLocker warning Mar 26, 2024 am 09:41 AM

This article will explore how to solve the problem of wrong password, especially the need to be careful when dealing with BitLocker warnings. This warning is triggered when an incorrect password is entered multiple times in BitLocker to unlock the drive. Usually, this warning occurs because the system has a policy that limits incorrect login attempts (usually three login attempts are allowed). In this case, the user will receive an appropriate warning message. The complete warning message is as follows: The password entered is incorrect. Please note that continuously entering incorrect passwords will cause the account to be locked. This is to protect the security of your data. If you need to unlock your account, you will need to use a BitLocker recovery key. The password is incorrect, beware the BitLocker warning you receive when you log in to your computer

How to set a password to log in to Douyin? Does setting a password to log in require facial recognition? How to set a password to log in to Douyin? Does setting a password to log in require facial recognition? Mar 21, 2024 pm 06:10 PM

With the popularity of Douyin, more and more users are beginning to use this platform to enjoy the fun of short videos. In order to protect the security of user accounts, Douyin provides a variety of login methods, among which password login is a common and important method. So, how to set a password to log in to Douyin? 1. How to set a password to log in to Douyin? 1. Open Douyin APP, click the "Me" button in the lower right corner to enter the personal homepage. 2. Under the personal homepage, find the "Settings" option and click to enter. 3. In the settings page, find the "Account and Security" option and click to enter. 4. On the Account and Security page, find the "Login Password" option and click to enter. 5. If a login password has not been set, the system will prompt you to set a login password. Enter the password you want to set

How to set router WiFi password using mobile phone (using mobile phone as tool) How to set router WiFi password using mobile phone (using mobile phone as tool) Apr 24, 2024 pm 06:04 PM

Wireless networks have become an indispensable part of people's lives in today's digital world. Protecting the security of personal wireless networks is particularly important, however. Setting a strong password is key to ensuring that your WiFi network cannot be hacked by others. To ensure your network security, this article will introduce in detail how to use your mobile phone to change the router WiFi password. 1. Open the router management page - Open the router management page in the mobile browser and enter the router's default IP address. 2. Enter the administrator username and password - To gain access, enter the correct administrator username and password in the login page. 3. Navigate to the wireless settings page - find and click to enter the wireless settings page, in the router management page. 4. Find the current Wi

How to use Passkey for your Microsoft account How to use Passkey for your Microsoft account Feb 19, 2024 am 11:03 AM

Passkey is a more advanced and secure way to log in and can be used with a Microsoft account. This article will guide you how to use Passkey in your Microsoft account, introduce its advantages and the differences with passwords. Before we get into the details, we emphasize that if you frequently forget your passwords or need to log in quickly, Passkey will generally be better for you. What is Passkey? How are they different from passwords? Passwords are an advanced and secure authentication method that can replace traditional password logins. Each application has a unique key, ensuring security and preventing threats like phishing. Users can confirm their identity via email and password, or use facial recognition, fingerprint or security key

What should I do if my Win10 password does not meet the password policy requirements? What to do if my computer password does not meet the policy requirements? What should I do if my Win10 password does not meet the password policy requirements? What to do if my computer password does not meet the policy requirements? Jun 25, 2024 pm 04:59 PM

In the Windows 10 system, the password policy is a set of security rules to ensure that the passwords set by users meet certain strength and complexity requirements. If the system prompts that your password does not meet the password policy requirements, it usually means that your password does not meet the requirements set by Microsoft. standards for complexity, length, or character types, so how can this be avoided? Users can directly find the password policy under the local computer policy to perform operations. Let’s take a look below. Solutions that do not comply with password policy specifications: Change the password length: According to the password policy requirements, we can try to increase the length of the password, such as changing the original 6-digit password to 8-digit or longer. Add special characters: Password policies often require special characters such as @, #, $, etc. I

How to easily get the WiFi password of a connected mobile phone (quickly find the WiFi password saved in the mobile phone) How to easily get the WiFi password of a connected mobile phone (quickly find the WiFi password saved in the mobile phone) May 08, 2024 pm 01:10 PM

Our mobile phones have become an integral part of our lives in modern society. Wireless network connections have also become an indispensable tool in our daily lives. However, sometimes we face such a situation: we want to connect to other devices but are unable to do so, we connect to WiFi but forget the password. How to easily get the WiFi password of a connected mobile phone? Find the saved WiFi password on the phone 1. Find the "WiFi" option in the settings, find and click it, and enter the phone's settings interface "WiFi" to enter the WiFi settings page, option. 2. Open the connected WiFi network details, find the name of the connected WiFi network, click to enter the detailed information page of the network, in the WiFi settings page. 3.

Tutorial on changing wifi password on mobile phone (simple operation) Tutorial on changing wifi password on mobile phone (simple operation) Apr 26, 2024 pm 06:25 PM

Wireless networks have become an indispensable part of our lives with the rapid development of the Internet. In order to protect personal information and network security, it is very important to change your wifi password regularly, however. To help you better protect your home network security, this article will introduce you to a detailed tutorial on how to use your mobile phone to change your WiFi password. 1. Understand the importance of WiFi passwords. WiFi passwords are the first line of defense to protect personal information and network security. In the Internet age, understanding its importance can better understand why passwords need to be changed regularly. 2. Confirm that the phone is connected to wifi. First, make sure that the phone is connected to the wifi network whose password you want to change before changing the wifi password. 3. Open the phone’s settings menu and enter the phone’s settings menu.

See all articles