The regular expression matching password can only be a combination of numbers and letters. [php and js implementation], String. js

Source: Internet
Author: User

The regular expression matching password can only be a combination of numbers and letters. [php and js implementation], String. js

The example in this article shows that the regular expression matching password can only be a combination of numbers and letters. We will share this with you for your reference. The details are as follows:

Password requirements:

1. Not all numbers
2. Not all letters
3. It must be a combination of numbers and letters
4. does not contain special characters
5. The password is a string of 6 to 30 characters.

/*** @ Desc get_pwd_strength () im: Judge the password structure based on the password string * @ param (string) $ mobile * return: $ msg */function get_pwd_strength ($ pwd) {if (strlen ($ pwd)> 30 | strlen ($ pwd) <6) {return "the password must be a string of 6 to 30 characters ";} if (preg_match ("/^ \ d * $/", $ pwd) {return "the password must contain letters; strength: weak "; // full number} if (preg_match ("/^ [a-z] * $/I", $ pwd) {return "the password must contain numbers, intensity: Medium "; // full letter} if (! Preg_match ("/^ [a-z \ d] * $/I", $ pwd) {return "the password can only contain numbers and letters. Strength: Strong "; // there are numbers and letters ";}}

Js Regular Expression matching

/*** Check the password strength. It must be a string of at least 6 Characters in combination with digits and letters. */$. CheckPwd = function (v) {v = $. trim (v); if (v. length <6 | v. length> 30) {return "the password length is 6-30 characters";} if (/^ \ d + $ /. test (v) {return "full number";} if (/^ [a-z] + $/I. test (v) {return "all letters";} if (! /^ [A-Za-z0-9] + $/. test (v) {return "can only contain numbers with letters";} return "correct ";};

PS: here we will provide two very convenient Regular Expression tools for your reference:

JavaScript Regular Expression online testing tool:
Http://tools.jb51.net/regex/javascript

Regular Expression generation tool:
Http://tools.jb51.net/regex/create_reg

I hope this article will help you learn regular expressions.

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.