Reputation: 51
I am new to regular expression. I need to validate the following using regular expression:
Upvotes: 1
Views: 10193
Reputation: 239693
You can use the following RegEx, \\d{6,10}
. This would match any string which has only digits and the number of times digits can occur is 6 to 10.
(By digit we mean any character with the Unicode General Category of Nd (Number, Decimal Digit.) as Java uses the ICU Regular Expressions libraries.)
You can see how the RegEx works here
String pattern = "\\d{6,10}", myString = "111111";
System.out.println(myString.matches(pattern));
would print
true
Upvotes: 7