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.