I am working with regexp in dart for my flutter project. the digit should be 11 digits and the first 2 digits should always start with 09 and the remaining 9 digits can be any numbers.
RegExp regExp = new RegExp(
r"(0/91)?[7-9][0-9]{9}");
if (regExp.hasMatch("09123979064")) {
print("valid");
} else {
print("invalid phone number");
}
CodePudding user response:
The (0/91)?[7-9][0-9]{9} regex matches an optional 0/91 substring capturing it into Group 1 and then matches 7, 8 or 9 digit, and then nine more digits anywhere inside the string.
You need
RegExp regExp = new RegExp("^09[0-9]{9}$");
where
^- start of string09- a09substring[0-9]{9}- nine digits$- end of string.
See the regex demo.
