Hi im trying to write a validation class using : regexp-me lib because of the answer of this post.
What did i do
String id = "123456789";
String pattern = "\\d{7,8}";
public boolean validate(String id,String pattern){
RE regular_expresion = new RE("\\d{7,8}");
return regular_expresion.match(id);
}
This code should have returned false with that "id" since the pattern just should accept 7 to 8 digits. However if i use id = "1234567" it return true , the code is accepting 7 or more digits.
The {m,n} is working as a {n,}.
Has someone had this problem before?
The expression
\\d{7,8}means:This is true for
1234567as this is a string of 7 digits as well as for123456789because also this string contains a string with 7 or 8 digits.Change the expression to
^\\d{7,8}$to get a positive result only when the entire string from beginning to end consists of only digits and the string length is either 7 or 8.