Home > Web Front-end > JS Tutorial > How to use the test() method for regular verification

How to use the test() method for regular verification

angryTom
Release: 2020-02-26 18:01:12
forward
2463 people have browsed it

In programming, we often encounter situations where user input needs to be verified. Regular expressions are usually used for verification. The test() method is used in js to verify the regular expressions. So how to use the test() method?

How to use the test() method for regular verification

How to use the test() method for regular verification

The test() method is used to detect whether a string Match a certain pattern

Recommendation:js tutorial

The regular verification of the invoice header in a business recently encountered is as follows:

console.log(/^[a-zA-Z\u4e00-\u9fa5\s()()<>《》\(\)\-]+$/.test("中国xxxx公司七五0试验场"))
Copy after login

When the user enters the company name above, an error occurs and the verification fails. This is because according to Chinese company regulations, Arabic numerals are not allowed in company names, so when 0 appears, the regular verification fails.

Company names shall not contain the following words:

1. Those that are harmful to the interests of the country and society;

2. Those that may cause deception or misunderstanding to the public;

3. Name of foreign country (region), name of international organization;

4. Name of political party, name of party, government and military organs, name of mass organization, name of social group and troop number;

5 , foreign characters, Chinese pinyin letters, Arabic numerals;

6, other laws and administrative regulations prohibiting.

For more JavaScript tutorials, please pay attention to the PHP Chinese websiteFront-end video tutorials.

The above is the detailed content of How to use the test() method for regular verification. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:cnblogs.com
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
Latest Issues
Where is js written?
From 1970-01-01 08:00:00
0
0
0
js addClass not working
From 1970-01-01 08:00:00
0
0
0
js file code not found
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template