How to use regular expressions to verify the registry
This time I will bring you the use of regular expressions to verify the registry and the precautionsof using regular expressions to verify the registry. The following are practical cases. , let’s take a look.
Regular expression
Regular expression is a logical formula for stringoperation, which is to use prior Some defined specific characters and the combination of these specific characters form a "rule string". This "rule string" is used to express a filtering logic for strings.
Purpose of regular expression
1. Whether the given string conforms to the filtering logic of the regular expression (called "matching") ;
2. We can get the specific part we want from the string through regular expressions.
The characteristics of regular expressions are
1. Flexibility, logic and functionality are very strong;
2. It can quickly achieve complex control of strings in an extremely simple way;
3. It is relatively obscure for those who are new to it.
Registry verification
1. Get id
function $(id){ return document.getElementById(id); }
2. Verify name
function checkName(){ //获取值 var username=$('user').value; //判断不能为空 if(username==''){ $('s1').innerHTML='用户名不能为空'; return false; } //正则表达式 var reg=/^[a-zA-Z][a-zA-Z0-9]{4,9}$/; //检测输入内容是否匹配正则表达式 if(!reg.test(username)){ $('s1').innerHTML='用户名必须是5-10位数字或字母组成,开头不能是数字'; return false; } //匹配,返回空 $('s1').innerHTML=''; return true; }
Remarks :s1 is the judgment prompt content, added after the input box
3.Verify password
function checkPwd(){ //获得值 同上… //判断不能为空 同上… //正则表达式 var reg=/^\S{6,}$/; //检测输入内容是否匹配正则表达式 if(reg.test(password)==false){ $('s2').innerHTML='密码必须是6位以上'; return false; } //匹配,返回空 同上… }
4.Verify email
function checkEmail(){ //获得值 同上… //判断不能为空 同上… //正则表达式 var reg=/^\w+@\w+\.com|cn|net$/; //检测输入内容是否匹配正则表达式 if(!reg.test(email)){ $('s3').innerHTML='邮箱不合法'; return false; } //匹配,返回空 同上… }
5.Verify mobile phone number
function checkTel(){ //获得值 同上… //判断不能为空 同上… //正则表达式 var reg=/^1[34578]\d{9}$/; //检测输入内容是否匹配正则表达式 if(!reg.test(tel)){ $('s4').innerHTML='手机号码不合法'; return false; } //匹配,返回空 同上… }
6.Verify ID number
function checkCid(){ //获得值 同上… //判断不能为空 同上… //正则表达式 var reg=/^\d{15}$|^\d{17}\d|x$/; //检测输入内容是否匹配正则表达式 if(!reg.test(cid)){ $('s5').innerHTML='身份证不合法'; return false; } //匹配,返回空 同上… }
7.Verify QQ number
function checkQQ(){ //获得值 同上… //判断不能为空 同上… //正则表达式 var reg=/^[1-9]\d{7,10}$/; //检测输入内容是否匹配正则表达式 if(!reg.test(qq)){ $('s6').innerHTML='QQ必须是8到11数字组成,开头不能是0'; return false; } //匹配,返回空 同上… }
8.Check all conditions
function checkAll(){ if(checkName()&&checkPwd()&&checkEmail()&&checkTel()&&checkCid()&&checkQQ()){ return true; }else{ return false; } }
Of course, in the later stage, you can use the jQuery Validate verification framework for expression verification, which is more convenient.
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!
Recommended reading:
How to use regular expressions to group strings
Use regular expressions to verify the input content of the login page
The above is the detailed content of How to use regular expressions to verify the registry. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Removing a Printer on Windows 11 Completely removing a printer requires two things - removing the printer itself, and then removing the driver. There are several ways you can perform these operations on Windows 11. They are: Method 1: From Settings Perhaps the most common method, a printer can be easily removed from the Windows Settings application. Here's how to do it: Press Win+I to open Settings. Then click Bluetooth & Devices in the left pane. On the right, click Printers & Scanners. Click the printer you want to uninstall. Select Delete. When prompted, click Yes. Method 2: Use Device Manager to Remove Printer Drivers Device Manager lets you manage and remove Windows

Location services are an important feature for some applications on Windows, depending on the location of your system. So if you see the Location Services option grayed out on your system, you can't even toggle it manually. Usually, some system glitch causes this issue and you can easily fix it by following these simple solutions. Fix 1 – Adjust the registry You can adjust the registry to fix this greyed out location services issue. 1. Press the Win key and type "Registry". 2. Then, click "Registry Editor" to open the Registry Editor on your system. 3. You will delete a specific registry subdirectory. Usually, it won't affect your system at all. However, it is recommended that you perform a system backup. one. After opening the Registry Editor, click

If you are a Windows user and want to disable the core parking functionality in your system, this article will guide you through the process. What is core parking? The core parking function is a power saving mechanism. It puts some of your processors into a sleep mode that doesn't perform any tasks and consumes very little or no power. This helps reduce energy consumption and therefore heat in the system. These cores are unparked when needed. Few users need to disable this feature, especially gamers. Disabling this feature will improve your system performance. Disable Windows Core Parking using Windows Registry Editor Step 1: Use Windows + R keys simultaneously to open the run prompt. Step 2: At the run prompt

If WDMyCloud is not showing up on the network in Windows 11, this can be a big problem, especially if you store backups or other important files in it. This can be a big problem for users who frequently need to access network storage, so in today's guide, we'll show you how to fix this problem permanently. Why doesn't WDMyCloud show up on Windows 11 network? Your MyCloud device, network adapter, or internet connection is not configured correctly. The SMB function is not installed on the computer. A temporary glitch in Winsock can sometimes cause this problem. What should I do if my cloud doesn't show up on the network? Before we start fixing the problem, you can perform some preliminary checks:

Jump list on Windows provides easy access to recent files. If you want to add jump list items on Windows, this tutorial will help you get started. Jump Lists on Windows 10 and Windows 11 allow easy access to recently used files, folders, and websites. However, you may want to display more than the 10 most recent items that Windows displays by default. You can make Windows display more items in your jump list by adjusting the registry. For example, you can set it to display about 15-20 items, which will display well on most monitors. This tutorial will show you how to use Windows 10 and Windows 10

Windows 11 comes with many features out of the box, as long as you attach a Microsoft account to them. When you clean install Windows 11, it asks you to set up Microsoft Office, OneDrive, Windows Hello, PhoneLinks (formerly YourPhone), and more. If you don't set up these Microsoft services, you will receive a message reminding you to complete the setup every few days. You can click Continue or Remind Me within 3 days. Both options are annoying, and there's no option to say no. Instead, you need to try a workaround. This is done on Windows by disabling "Let

How to Block Notifications on Windows 11 You can easily block notifications on Windows 11 by following the steps below. To block your notifications: Open the Start menu and select Settings. Alternatively, you can directly press Windows key + I to open Settings. When settings open, click System in the list on the left, then click Notifications on the right. On the following screen, turn off notification options. Exit the Settings application. Going forward, application and system notifications will stop showing on the desktop. However, it's worth noting that some apps have their own built-in notification settings. In this case, you'll need to disable notifications directly from the app - but this is rare. By turning off notifications in Settings, you will eliminate

Click to enter: ChatGPT tool plug-in navigation. Ordinary Windows users may never have to access the Windows registry, but various applications and Windows services do. If the registry keys go bad, you will experience various issues such as higher CPU usage, random system crashes, extended startup and shutdown times, and sub-par global performance. Needless to say, the registry must remain functioning properly. What is the Windows Registry? The Windows Registry is a system-wide repository of files and settings that stores important information about Windows, user preferences, applications, hardware, and many other important parts that make up your personal computer. This data is stored in "
