public class RegExTest {
public static void main(String arg[]) {
String str = "0888"; //"+91989898" "9180709709"
String regex="^([\\+](91))+([0-9]+$)|(^(0))+([0-9]+$)"; //{10} if you want to give no limit
Pattern pat = Pattern.compile(regex);
Matcher mat= pat.matcher(str);
if (mat.matches()) {
System.out.println("String matched");
} else {
System.out.println("String not matched");
}
}
}
To give number limit use this regex:
String regex="^([\\+](91))+([0-9]{10}$)|(^(0))+([0-9]{10}$)";
Here {10} means after 0 or +91 must be 10 number
No comments:
Post a Comment