如何检查电话号码是否有效?它的长度为13(包括前面的字符 +
)。
我该怎么做?
我试过了:
String regexStr = "^[0-9]$";
String number=entered_number.getText().toString();
if(entered_number.getText().toString().length()<10 || number.length()>13 || number.matches(regexStr)==false ) {
Toast.makeText(MyDialog.this,"Please enter "+"\n"+" valid phone number",Toast.LENGTH_SHORT).show();
// am_checked=0;
}`
我还试过这个:
public boolean isValidPhoneNumber(String number)
{
for (char c : number.toCharArray())
{
if (!VALID_CHARS.contains(c))
{
return false;
}
}
// All characters were valid
return true;
}
两个都不管用。
输入类型: + sign to be accepted and from 0-9 numbers and length b/w 10-13 and should not accept other characters