Home Backend Development PHP Tutorial Organizing regular expression registry verification notes

Organizing regular expression registry verification notes

Dec 05, 2017 pm 01:58 PM
Registry notes expression

Regular expression is a logical formula for string operations. It uses some predefined specific characters and combinations of these specific characters to 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 " Match");

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 the id

function $(id){
  return document.getElementById(id);
}
Copy after login

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;
}
Copy after login

Note: 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;
  }
  //匹配,返回空
    同上…
}
Copy after login

4.Verify email

function checkEmail(){
  //获得值
    同上…
  //判断不能为空
    同上…
  //正则表达式
  var reg=/^\w+@\w+\.com|cn|net$/;      
  //检测输入内容是否匹配正则表达式
  if(!reg.test(email)){
    $('s3').innerHTML='邮箱不合法';
    return false;
  }
  //匹配,返回空
    同上…
}
Copy after login

5. Verify mobile phone number

function checkTel(){
  //获得值
    同上…
  //判断不能为空
    同上…
  //正则表达式
  var reg=/^1[34578]\d{9}$/;     
  //检测输入内容是否匹配正则表达式
  if(!reg.test(tel)){
    $('s4').innerHTML='手机号码不合法';
    return false;
  }
  //匹配,返回空
    同上…
}
Copy after login

6.Verify ID number

function checkCid(){
  //获得值
    同上…
  //判断不能为空
    同上…
  //正则表达式
  var reg=/^\d{15}$|^\d{17}\d|x$/;     
  //检测输入内容是否匹配正则表达式
  if(!reg.test(cid)){
    $('s5').innerHTML='身份证不合法';
    return false;
  }
  //匹配,返回空
    同上…
}
Copy after login

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;
      }
  //匹配,返回空
    同上…
}
Copy after login

8. Detect all conditions

function checkAll(){
  if(checkName()&&checkPwd()&&checkEmail()&&checkTel()&&checkCid()&&checkQQ()){
    return true;
  }else{
    return false;
  }
}
Copy after login

Of course, in the later stage, you can use the jQuery Validate verification framework for expression verification, which is more convenient.

The above content is a compilation of regular expression registry verification notes. I hope it can help everyone.

Related recommendations:

The most complete PHP regular expression in history_regular expression

The concept and use of regular expressions in JavaScript Application_regular expression

PHP regular expression collection

The above is the detailed content of Organizing regular expression registry verification notes. 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

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.

Undress AI Tool

Undress AI Tool

Undress images for free

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)

Remove a printer on Windows 11: 6 methods and 7 fix instructions Remove a printer on Windows 11: 6 methods and 7 fix instructions Apr 17, 2023 am 09:37 AM

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

How to solve the problem of location services being grayed out in Windows 10/11? How to solve the problem of location services being grayed out in Windows 10/11? Apr 26, 2023 pm 03:49 PM

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

How to disable core parking on Windows 10 How to disable core parking on Windows 10 May 16, 2023 pm 01:07 PM

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

Fix: WD My Cloud doesn't show up on the network in Windows 11 Fix: WD My Cloud doesn't show up on the network in Windows 11 Oct 02, 2023 pm 11:21 PM

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:

How to delete Xiaohongshu notes How to delete Xiaohongshu notes Mar 21, 2024 pm 08:12 PM

How to delete Xiaohongshu notes? Notes can be edited in the Xiaohongshu APP. Most users don’t know how to delete Xiaohongshu notes. Next, the editor brings users pictures and texts on how to delete Xiaohongshu notes. Tutorial, interested users come and take a look! Xiaohongshu usage tutorial How to delete Xiaohongshu notes 1. First open the Xiaohongshu APP and enter the main page, select [Me] in the lower right corner to enter the special area; 2. Then in the My area, click on the note page shown in the picture below , select the note you want to delete; 3. Enter the note page, click [three dots] in the upper right corner; 4. Finally, the function bar will expand at the bottom, click [Delete] to complete.

How to add jump list items on Windows 10 and 11 How to add jump list items on Windows 10 and 11 May 11, 2023 pm 04:31 PM

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

How to turn off notifications on Windows 11? How to turn off notifications on Windows 11? Apr 23, 2023 pm 01:28 PM

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

How to disable 'Let's finish setting up the device' on Windows How to disable 'Let's finish setting up the device' on Windows May 12, 2023 pm 10:43 PM

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

See all articles