用户密码为6~16字符
Posted 大前端圈
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了用户密码为6~16字符相关的知识,希望对你有一定的参考价值。
/**
* 用户密码为6~16字符,可使用字母(区分大小写)、数字与特殊符号 用户密码至少包含字母、数字、符号中的两种
*
*
*/
public class PasswordValidate
public static String validatePassword(String password, int type)
// type == 1 不带验证的密码
// type == 2 非纯数字的密码
if (password.length() < 6 || password.length() > 16)
return "密码为6~16字符";
/*
* else if(doExcute(password) < 2) return "用户密码为6~16字符";
*/
else
if (type == 2)
if (doExcute(password) >= 2)
return "1";
else
return "密码为6~16字符,包含字母、数字或特殊字符";
return null;
public static int doExcute(String password)
int kindOfCharacter = 0;
String digital = "[0-9]";
String capital = "[A-Z]";
String lowercase = "[a-z]";
String spec = "[-~!@#$%^&*()_+|:<>?;',.]";
/** 有大写字母或小写字母,即有字母 */
for (int i = 0; i < password.length(); i++)
if (password.substring(i, i + 1).matches(capital)
|| password.substring(i, i + 1).matches(lowercase))
System.out.println(password.substring(i, i + 1));
kindOfCharacter++;
break;
/** 有数字 */
for (int i = 0; i < password.length(); i++)
if (password.substring(i, i + 1).matches(digital))
kindOfCharacter++;
break;
/** 有符号 */
for (int i = 0; i < password.length(); i++)
if (password.substring(i, i + 1).matches(spec))
kindOfCharacter++;
break;
if (password.length() < 6)
kindOfCharacter = 1;
return kindOfCharacter;
以上是关于用户密码为6~16字符的主要内容,如果未能解决你的问题,请参考以下文章
谁能给我一个正确的登录名和密码,密码必须是6~16位字符(字母、数字、符号),区分大小写!!
php验证密码 必须为6-16位字母数字符号组合, 正则表达式 着急,在线等