Validación de número de teléfono Android
¿Cómo verifico si un número de teléfono es válido o no? Tiene hasta 13 de longitud (incluido el carácter+
Al frente)
¿Cómo puedo hacer eso
Intenté esto:
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;
}`
Y también probé esto:
public boolean isValidPhoneNumber(String number)
{
for (char c : number.toCharArray())
{
if (!VALID_CHARS.contains(c))
{
return false;
}
}
// All characters were valid
return true;
}
Ambas no funcionan.
Tipo de entrada:+ sign to be accepted and from 0-9 numbers and length b/w 10-13 and should not accept other characters