Android 手机号,密码正则验证
*accont—->手机号 以1开头,10位结尾。哈哈,还有其他各种写法,我这里使用了简单的。
*password—->密码 6到18位的字母大小写及数字下划线。
参考菜鸟教程Java正则
public class ppp {
public static boolean isMobileNO(String accont) {
Pattern p = Pattern.compile("^1\\d{10}$");
Matcher m = p.matcher(username);
return m.matches();
}
public static boolean isPasswordNO(String password) {
Pattern p = Pattern.compile("[0-9a-zA-Z_]{6,18}");
Matcher m = p.matcher(password);
return m.matches();
}
}
请求这里我是这样判断的
private void initView() {
mBtnLogin = (TextView) findViewById(R.id.main_btn_login);
user_username = (EditText) findViewById(R.id.username);
user_password = (EditText) findViewById(R.id.password);
mBtnLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
account = user_username.getText().toString();
password = user_password.getText().toString();
if (TextUtils.isEmpty(account)) {
Toast.makeText(getApplicationContext(),"请输入账号",Toast.LENGTH_SHORT).show();
return;
}
if (!ppp.isMobileNO(account)) {
Toast.makeText(getApplicationContext(),"账号或密码错误",Toast.LENGTH_SHORT).show();
return;
}
if (TextUtils.isEmpty(password)) {
Toast.makeText(getApplicationContext(),"请输入密码",Toast.LENGTH_SHORT).show();
return;
}
if (!ppp.isPasswordNO(password)) {
user_password.setText(R