mirror of
https://gitee.com/willfree/min-vpn-client_v2.git
synced 2026-06-03 15:36:14 +08:00
更新验证用户名的正则表达式
This commit is contained in:
@@ -161,7 +161,7 @@ public class LoginActivity extends MINVpnBaseActivity<LoginActivityPresenter>
|
||||
return;
|
||||
}
|
||||
if (!AccountValidatorRegexUtil.INSTANCE.isUsername(rawUsername)) {
|
||||
showWarning("请输入有效的用户名,用户名长度需要大于0小于20");
|
||||
showWarning("请输入有效的用户名,用户名长度需要在[3,20]之间,包含字母、数字、下划线,且以字母开头");
|
||||
btnLogin.revertAnimation();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ public class RegisterActivity extends MINVpnBaseActivity<RegisterActivityPresent
|
||||
return;
|
||||
}
|
||||
if(!AccountValidatorRegexUtil.INSTANCE.isUsername(username)){
|
||||
showWarning("请输入有效的用户名,用户名长度需要大于0小于20");
|
||||
showWarning("请输入有效的用户名,用户名长度需要在[3,20]之间,包含字母、数字、下划线,且以字母开头");
|
||||
btnRegister.revertAnimation();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -8,8 +8,9 @@ import java.util.regex.Pattern
|
||||
object AccountValidatorRegexUtil {
|
||||
/**
|
||||
* 正则表达式:验证用户名
|
||||
* 长度在[3,20]之间,第一个字符为字母,所有字母是字母、数字或下划线
|
||||
*/
|
||||
val REGEX_USERNAME = "^[a-zA-Z]\\w{5,20}$"
|
||||
val REGEX_USERNAME = "^[a-zA-Z]\\w{2,20}$"
|
||||
|
||||
/**
|
||||
* 正则表达式:验证密码
|
||||
@@ -63,13 +64,13 @@ object AccountValidatorRegexUtil {
|
||||
|
||||
/**
|
||||
* 校验用户名
|
||||
*
|
||||
* 长度在[3,20]之间,仅支持字母、数字、下划线,且需要以字母开头
|
||||
* @param username
|
||||
* @return 校验通过返回true,否则返回false
|
||||
*/
|
||||
fun isUsername(username: String): Boolean {
|
||||
//return Pattern.matches(REGEX_USERNAME, username)
|
||||
return username.length > 0 && username.length < 20
|
||||
return (username.length >= 3 && username.length <= 20)
|
||||
&& Pattern.matches(REGEX_USERNAME, username)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.pkusz.min_vpn_client.utils;
|
||||
/*
|
||||
* @Author: Wang Feng
|
||||
* @Description:
|
||||
* @Version: 1.0.0
|
||||
* @Date: 15:59 2021/8/2
|
||||
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
|
||||
*/
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestAccountValidator {
|
||||
/**
|
||||
* 测试验证用户名的正则表达式
|
||||
*/
|
||||
@Test
|
||||
public void testValidUsername(){
|
||||
String testStr="w12W";
|
||||
System.out.println("len: "+testStr.length());
|
||||
boolean isTrue=AccountValidatorRegexUtil.INSTANCE.isUsername(testStr);
|
||||
System.out.println(isTrue);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user