关于登录的客户端验证

passText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);

/**
* 显示与隐藏密码
*/
private void showOrHidePwd() {
int type = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD;
if (passText.getInputType() == type) {
passText.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
passText.setSelection(passText.getText().length()); //把光标设置到当前文本末尾
pwdShow.setImageResource(R.drawable.invisible);
} else {
passText.setInputType(type);
passText.setSelection(passText.getText().length());
pwdShow.setImageResource(R.drawable.visible);
}
}
// 判断是否为手机号
private boolean isPhone(String inputText) {
Pattern p = Pattern
.compile("((13[0-9])|(15[4,\D])|(18[0,5-9]))\d{8}$");//需新增号段181等
Matcher m = p.matcher(inputText);
return m.matches();
}

// 判断格式是否为email
private boolean isEmail(String email) {
String str = "^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$";
Pattern p = Pattern.compile(str);
Matcher m = p.matcher(email);
return m.matches();
}
// 验证是否为昵称
private boolean isHoneyname(String honeyname) {
if (honeyname == null || honeyname.length() == 0) {
return false;
}
int len = 0;
char[] honeychar = honeyname.toCharArray();
for (int i = 0; i < honeychar.length; i++) {
if (isChinese(honeychar[i])) {
len += 2;
} else {
len += 1;
}
}
if (len < 4 || len > 18) {
//"正确的昵称应该为\n1、4-18个字符\n2、2-6个汉字\n3、不能是邮箱和手机号"
return false;
}
return true;
}
private boolean isChinese(char c) {
Character.UnicodeBlock ub = Character.UnicodeBlock.of(c);
if (ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS
|| ub == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS
|| ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A
|| ub == Character.UnicodeBlock.GENERAL_PUNCTUATION
|| ub == Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION
|| ub == Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS) {
return true;
}
return false;
}

你可能感兴趣的:(关于登录的客户端验证)