1.写一个工具类来验证手机号和密码
public class YZUtils {
public static boolean IsPhone(String phone){
String phoneYZ="^((13[0-9])|(14[5,7])|(15[0-3,5-9])|(17[0,3,5-8])|(18[0-9])|166|198|199|(147))\\d{8}$";
if (TextUtils.isEmpty(phone)){
return false;
}
else {
return phone.matches(phoneYZ);
}
}
public static boolean IsPwd(String pwd){
String pwdYZ="^[0-9a-zA-Z]{6,20}$";
if (TextUtils.isEmpty(pwd)){
return false;
}else {
return pwd.matches(pwdYZ);
}
}
}
2 登录按钮的点击事件
@OnClick(R.id.login_but)
void onclick5(){
//phone_edit.getText().toString() 是获取手机号的内容
if (YZUtils.IsPhone(phone_edit.getText().toString())){
Toast.makeText(MainActivity.this,"手机号格式正确",Toast.LENGTH_SHORT).show();
}else {
Toast.makeText(MainActivity.this,"手机号格式不正确",Toast.LENGTH_SHORT).show();
}
//pwd_edit.getText().toString() 是获取密码的内容
if (YZUtils.IsPwd(pwd_edit.getText().toString())){
Toast.makeText(MainActivity.this,"密码格式正确",Toast.LENGTH_SHORT).show();
}else {
Toast.makeText(MainActivity.this,"密码格式不正确",Toast.LENGTH_SHORT).show();
}
}
正则表达式验证手机号 密码
最新推荐文章于 2023-10-14 13:37:49 发布