In js, the regular expression is used to search for letters and numbers.

Source: Internet
Author: User

In js, the regular expression is used to search for letters and numbers.

Let's not talk about it. Let's take a look at how to use regular expressions to search for letters and numbers in Javascript. The specific code is as follows:

<! Doctype html> 

The following describes how to use a regular expression to verify that the password contains numbers and letters.

The script must contain at least one digit and one letter as follows:

Function CheckPassWord (password) {// The password must contain numbers and letters var str = password; if (str = null | str. length <8) {return false;} var reg = new RegExp (/^ (?! [^ A-zA-Z] + $ )(?! \ D + $)/); if (reg. test (str) return true ;}

It must contain numbers and letters, and cannot contain special symbols. The script method is as follows:

Function CheckPassWord (password) {// it must be a letter with a number and a length of no less than 8 characters var str = password; if (str = null | str. length <8) {return false;} var reg1 = new RegExp (/^ [0-9A-Za-z] + $/); if (! Reg1.test (str) {return false;} var reg = new RegExp (/[A-Za-z]. * [0-9] | [0-9]. * [A-Za-z]/); if (reg. test (str) {return true;} else {return false ;}}

Now, it's over. I hope it will help you!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.