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

Using php and js to implement regular password matching of numbers and letters

php中世界最好的语言
Release: 2018-03-29 18:01:21
Original
2650 people have browsed it

This time I will bring you how to use php and js to regularly match passwords with numbers and letters. Use php and js to regularly match passwords with numbers and letters. Let’s take a look at the case. The example in this article describes the function of regular matching passwords that can only be a combination of numbers and letters. Share it with everyone for your reference, the details are as follows:

Password requirements:

1. It cannot be all numbers

2. It cannot be all letters3. Must be a combination of numbers and letters
4. Does not contain
special characters
5. The password must be a string of 6-30 characters

/**
 * @desc get_pwd_strength()im:根据密码字符串判断密码结构
 * @param (string)$mobile
 * return 返回:$msg
 */
function get_pwd_strength($pwd){
  if (strlen($pwd)>30 || strlen($pwd)<6)
  {
    return "密码必须为6-30位的字符串";
  }
  if(preg_match("/^\d*$/",$pwd))
  {
    return "密码必须包含字母,强度:弱";//全数字
  }
  if(preg_match("/^[a-z]*$/i",$pwd))
  {
    return "密码必须包含数字,强度:中";//全字母
  }
  if(!preg_match("/^[a-z\d]*$/i",$pwd))
  {
    return "密码只能包含数字和字母,强度:强";//有数字有字母 ";
  }
}
Copy after login
js Regular matching

/**
 * 检测密码强度,必须由数字与字母组合,至少6位的字符串。
 */
$.checkPwd = function(v){
 v=$.trim(v);
 if(v.length<6||v.length>30){
    return "密码长度为6-30位";
  }
  if(/^\d+$/.test(v))
  {
    return "全数字";
  }
  if(/^[a-z]+$/i.test(v))
  {
    return "全字母";
  }
  if(!/^[A-Za-z0-9]+$/.test(v))
  {
    return "只能含有数字有字母";
  }
  return "正确";
};
Copy after login

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the PHP Chinese website!

Recommended reading:

How to match consecutive numbers with regular expressions


##Development experience of implementing minimum matching with regular expressions

The above is the detailed content of Using php and js to implement regular password matching of numbers and letters. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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!