-2

How to validate mobile number using regular expression. mobile number must starts with non zero number and contains only 10 digits

Shardul
  • 4,266
  • 3
  • 32
  • 50

2 Answers2

1

Try something like:

System.out.println("1000000000".matches("^[1-9][0-9]{9}$"));
System.out.println("0000000030".matches("^[1-9][0-9]{9}$"));
System.out.println("000000003301".matches("^[1-9][0-9]{9}$"));

Output:
true
false
false
SMA
  • 36,381
  • 8
  • 49
  • 73
0

I don't see why you would need an RE(If you really do, read almas's answer), you mentioned java and android, a simple method like this should do (Assuming you have the number as a string "num"):

private boolean validateNumber(String num) {
    if(num.length = 10 && !num[0].equals("0")){
        return true;
    } else {
        return false;
    }
}