I am new to regular expression. I need to validate the following using regular expression:
- an input string is digit only between 6 and 10 characters long
I am new to regular expression. I need to validate the following using regular expression:
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
String#matches(); it acts as if the anchors are already there (if you don't believe me, try it out).