Home Web Front-end JS Tutorial Verify the ID number and email address and determine what the selected regular pattern of checked looks like.

Verify the ID number and email address and determine what the selected regular pattern of checked looks like.

Mar 29, 2018 pm 02:35 PM
Mail

This time I will bring you the regular rules for verifying the ID number and email address and judging the checked selection. The regular rules for verifying the ID number and email address and judging the checked selection Notes What are they? Here are actual cases. Let’s take a look.

The project happened to write about login and registration. When using the blur event to verify the user input, a bug appeared. Finally, the user input value was obtained in the onclick event of the registration button for verification.

Judge the checked status:

if(!$('#checkedAgree').prop("checked"){ 
   console.log('no');//未选中 
}else{ 
   console.log('yes');//选中 
} 
//注册 
$(".regBtn").on('click',function(){ 
  var regUser = $('#regUser').val();//用户名 
  var regPass = $('#regPass').val();//密码 
  var regAgainpass = $('#regAgainpass').val();//确认密码 
  var regTrueName = $('#regTrueName').val();//真实姓名 
  var idNumber = $('#idNumber').val();//身份证 
  var email = $('#email').val();//邮箱 
  if(!regUser){ 
    alert("用户名为空,请输入用户名"); 
  }else if(!regPass || regPass.length < 6){ 
    alert("密码为空或长度少于6位,请输入正确的密码"); 
  }else if(!regAgainpass || regAgainpass != regPass){ 
    alert("确认密码为空或两次密码输入不一致,请输入正确的密码"); 
  }else if(!regTrueName){ 
    alert("真实姓名为空,请输入真实姓名"); 
  }else if(!idNumber || !idNum(idNumber)){//调用身份证验证方法 
    alert("身份证号码不正确,请输入正确的身份证号码"); 
  }else if(!email || !emailNum(email)){//调用邮箱验证方法 
    alert("邮箱不正确,请输入正确的邮箱email"); 
  }else if(!$('#checkedAgree').prop("checked")){//判断用户同意注册协议状态 
    alert("您还未同意用户注册协议"); 
  }else{ 
    console.log('yes'); 
    //some code here 
  } 
}); 
//身份号码验证 
function idNum(idNum){ 
  var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/; 
  if(!reg.test(idNum)){ 
    return false; 
  }else{ 
    return true; 
  } 
} 
//邮箱验证 
function emailNum(emailNum){ 
  var reg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/;//验证身份证号 
  if(!reg.test(emailNum)){ 
    return false; 
  }else{ 
    return true; 
  } 
}
Copy after login

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 verify C# with regular expressions

The use of regular expressions and three major Linux text processing tools Detailed explanation

The above is the detailed content of Verify the ID number and email address and determine what the selected regular pattern of checked looks like.. 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)

Is the syntax of adding columns in different database systems the same? Is the syntax of adding columns in different database systems the same? Apr 09, 2025 pm 12:51 PM

The syntax for adding columns in different database systems varies greatly, and varies from database to database. For example: MySQL: ALTER TABLE users ADD COLUMN email VARCHAR(255); PostgreSQL: ALTER TABLE users ADD COLUMN email VARCHAR(255) NOT NULL UNIQUE;Oracle: ALTER TABLE users ADD email VARCHAR2(255);SQL Server: ALTER TABLE users ADD email VARCH

What are the Redis memory data types? What are the Redis memory data types? Apr 10, 2025 pm 02:06 PM

Redis provides five core memory data types: String: basic string storage, supporting incremental/decreasing operations. List: Bidirectional linked list, efficient insertion/deletion operation. Set: Unordered set, used for deduplication operations. Hash: Key-value pair storage, suitable for storing structured data. Zset: Ordered set, each element has fractions, and can be sorted by fractions. Choosing the right data type is critical to optimizing performance.

How to simplify email marketing with Composer: DUWA.io's application practices How to simplify email marketing with Composer: DUWA.io's application practices Apr 18, 2025 am 11:27 AM

I'm having a tricky problem when doing a mail marketing campaign: how to efficiently create and send mail in HTML format. The traditional approach is to write code manually and send emails using an SMTP server, but this is not only time consuming, but also error-prone. After trying multiple solutions, I discovered DUWA.io, a simple and easy-to-use RESTAPI that helps me create and send HTML mail quickly. To further simplify the development process, I decided to use Composer to install and manage DUWA.io's PHP library - captaindoe/duwa.

How to monitor debian mail server How to monitor debian mail server Apr 12, 2025 pm 10:06 PM

To ensure that your Debian mail server runs stably, an effective monitoring mechanism is required. This article introduces several monitoring methods, including log checking, monitoring tools and alarm system settings. 1. Log monitoring The log files of the Debian mail server are usually located in the /var/log/ directory, such as /var/log/mail.log. Regularly checking these logs can help you identify potential problems in a timely manner. 2. Monitoring tools and script examples The following provides several Bash script examples for monitoring CPU, memory and disk space usage and sending email alarms: 1. CPU usage monitoring: #!/bin/bashTHRESHOLD=80EMAILS="your_emai

Nginx virtual host configuration skills, efficiently manage multiple websites Nginx virtual host configuration skills, efficiently manage multiple websites Apr 13, 2025 pm 10:03 PM

Nginx virtual host configuration: Playing around your server garden Have you ever thought about how one server elegantly serves multiple websites at the same time? The answer is the Nginx virtual host configuration. This article will take you into Nginx virtual host configuration tips, allowing you to efficiently manage your "server garden" and avoid some common pitfalls. After reading, you will be able to easily configure the virtual host, understand the mechanism behind it, and write efficient and stable Nginx configuration files. Basic preparation: Don't forget that before starting your toolbox, you need to make sure that Nginx is installed and have some understanding of the basic Linux commands and configuration file structure. We won't explain how to install Nginx here, assuming you've completed this step. remember

How Navicat batch modify text data How Navicat batch modify text data Apr 08, 2025 pm 08:27 PM

Navicat provides tips for batch modifying text data: use SQL statements to perform precise modifications through query generators. Simple text replacement with the help of data import/export. Edit data directly in the Data Grid view for small-scale modifications. Common pitfalls of batch modification: SQL injection risk: filtering and escaping user input. Data type mismatch: Make sure the data type matches. Transaction processing: Use transaction processing to ensure data consistency. Error handling: Use the error handling mechanism and record the error message.

What factors need to be considered for SQL deleting rows What factors need to be considered for SQL deleting rows Apr 09, 2025 pm 12:12 PM

When considering deleting SQL lines, you should be aware of the following: Understand how DELETE statements work and do not confuse them with TRUNCATE or DROP. Use the WHERE clause to specify exactly the rows to be deleted to avoid mistaken deletion. Use batch deletion and transactions as needed to improve efficiency and ensure data consistency. Operate with caution, back up data, and use a test environment to avoid data loss.

How to add columns in SQL at the end of a table? How to add columns in SQL at the end of a table? Apr 09, 2025 pm 01:27 PM

Adding columns at the end of a database table is not easy, the specific operation depends on the database system, table size and data volume. Common errors include: ignoring data types, incorrectly using indexes, and concurrent operations. Optimization strategies include: selecting the appropriate storage engine, using partition tables, and utilizing database replication technology. Good code readability and maintainability also help avoid problems. Only by operating with caution and paying attention to the underlying mechanism can we avoid risks in data security and integrity.

See all articles