我正在实施一个Android应用程序,我想验证手机号码,但是我接替了我的代码:
final String regexStr = "^(?:(?:\\+|0{0,2})91(\\s*[\\-]\\s*)?|[0]?)?[789]\\d{9}$";
final EditText chmobno = (EditText)login.findViewById(R.id.chmobno);
mb=chmobno.getText().toString();
点击按钮
btnLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if( mb.matches(regexStr)){
Toast.makeText(MainActivity.this,
"Login Sucessfull", Toast.LENGTH_LONG).show();
login.cancel();
Intent i=new Intent(MainActivity.this,TSO_Home.class);
startActivity(i);
}
else{
Toast.makeText(MainActivity.this,
"Please enter Valid Mobile Number", Toast.LENGTH_LONG).show();
}
当我输入有效号码时,它会转到其他部分..请帮我找错误
答案 0 :(得分:1)
final String regexStr = "^(?:(?:\\+|0{0,2})91(\\s*[\\-]\\s*)?|[0]?)?[789]\\d{9}$";
final EditText chmobno = (EditText)login.findViewById(R.id.chmobno);
mb=chmobno.getText().toString();
btnLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if( mb.matches(regexStr)){
Toast.makeText(MainActivity.this,
"Login Sucessfull", Toast.LENGTH_LONG).show();
login.cancel();
Intent i=new Intent(MainActivity.this,TSO_Home.class);
startActivity(i);
}
else{
Toast.makeText(MainActivity.this,
"Please enter Valid Mobile Number", Toast.LENGTH_LONG).show();
}