-2

I want to validate my edit text which is already accepting numbers. But I want only specific numbers to be taken as starting value. For example : only numbers like 7,8 and 9 should be accepted as the first digit and then rest nine numbers can be any from 0-9

Vismay Patil
  • 64
  • 4
  • 14
  • get the number ,identify length of number , multiply by 10 with length of number.And finally divide the number with (length*10) ... you get the number and validate using if – sushildlh Aug 13 '16 at 10:15
  • check out my answer below will work perfect for you – Abhishek Aug 13 '16 at 10:18

3 Answers3

1
   /** Number Format Validation method  */
    public boolean isValidPhoneNumber(String mobile) {
        String regEx = "^[7-9][0-9]{9}$";
        return mobile.matches(regEx);
    }
Abhishek
  • 1,654
  • 2
  • 18
  • 31
0

You can use this function to check if the starting char is of your required value.

public boolean checkChar(){
char x = edittext.getText().toString().charAt(0);

if(x == '7' || x == '8' || x == '9')
 return true;

return false;
}
M.Waqas Pervez
  • 2,492
  • 2
  • 19
  • 33
0

You can use this function.

public boolean validate(){
String val = edittext.getText().toString();
if(val.length()!=10)
{
  Log.d("TAG","validation failed");
return false;    }
char x = val.charAt(0);

if(x == '7' || x == '8' || x == '9')
 return true;

return false;
}
Yogesh Rathi
  • 6,331
  • 4
  • 51
  • 81