相关疑难解决方法(0)

电话号码验证Android

如何检查电话号码是否有效?长度达到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;
}`
Run Code Online (Sandbox Code Playgroud)

我也试过这个:

public boolean isValidPhoneNumber(String number)
{
     for (char c : number.toCharArray())
     {
         if (!VALID_CHARS.contains(c))
         {
            return false;
         }
     }
     // All characters were valid
     return true;
}
Run Code Online (Sandbox Code Playgroud)

两者都不起作用.

输入类型: + sign to be accepted and from 0-9 numbers and length b/w 10-13 and should not accept other characters

validation android phone-number

51
推荐指数
7
解决办法
9万
查看次数

标签 统计

android ×1

phone-number ×1

validation ×1