Home > Web Front-end > JS Tutorial > body text

Example of string verification using regular expressions in javascript

高洛峰
Release: 2017-01-14 09:56:43
Original
1057 people have browsed it

var reg=/regular expression/;
boolean reg.test(string to be verified);
js engine will convert /regular expression/"" into a RegExp object, when the string If the requirements of the regular expression are met, true will be returned.
An expression verification example I wrote: The function is as follows:
User name, cannot be empty
Password 6 is a number
Password confirmation, the password entered twice must be the same
ID card number must It is 15 digits, or 18 digits, and the end can also be Please pay attention to PHP Chinese website!

source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!