Comment vérifier si un numéro de téléphone est valide ou non ? Il a une longueur maximale de 13 (y compris le caractère +
devant).
Comment je fais ça?
J'ai essayé ceci :
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;
}`
Et j'ai aussi essayé ceci :
public boolean isValidPhoneNumber(String number)
{
for (char c : number.toCharArray())
{
if (!VALID_CHARS.contains(c))
{
return false;
}
}
// All characters were valid
return true;
}
Les deux ne fonctionnent pas.
Type d'entrée : + sign to be accepted and from 0-9 numbers and length b/w 10-13 and should not accept other characters