正则判断账号密码(指定数字,字母,位数)
创建控件: number = (EditText) findViewById(R.id.number);
pass = (EditText) findViewById(R.id.pass);
pass = (EditText) findViewById(R.id.pass);
判断:
String name = this.number.getText().toString();
String psw = this.pass.getText().toString();
String names = "[1][3,5][5,2,7][0-9]{8}";
String psws = "[a-zA-Z]{1,}";
boolean matches = Pattern.matches(names, name);
boolean matches1 = Pattern.matches(psws, psw);
if(matches == true && matches1==true){
Toast.makeText(HomeActivity.this, "登陆成功", Toast.LENGTH_SHORT).show();
}else {
Toast.makeText(HomeActivity.this, "登录失败", Toast.LENGTH_SHORT).show();
};
String psw = this.pass.getText().toString();
String names = "[1][3,5][5,2,7][0-9]{8}";
String psws = "[a-zA-Z]{1,}";
boolean matches = Pattern.matches(names, name);
boolean matches1 = Pattern.matches(psws, psw);
if(matches == true && matches1==true){
Toast.makeText(HomeActivity.this, "登陆成功", Toast.LENGTH_SHORT).show();
}else {
Toast.makeText(HomeActivity.this, "登录失败", Toast.LENGTH_SHORT).show();
};