Home  >  Article  >  Web Front-end  >  Example of string verification using regular expressions in javascript

Example of string verification using regular expressions in javascript

高洛峰
高洛峰Original
2017-01-14 09:56:431072browse

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!

Statement:
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