Neh Agarwal wrote:I need to validate product version entered by the user. The allowed pattern is any alphanumeric and a dot, i.e allowed values are:
I am using the pattern as ^(\\w+.?\\w+)+$
The only problem with the ablove pattern is if the user gives only 1 digit or 1 letter, it fails to be matched
Can you please suggest a valid pattern.
Thanks, Please Help!
Correct, that is because you used \\w+ twice, so, the minimum length of a String must be 2 to be matched.
Also note that the short-hand-character-class \w matches an underscore as well. If this is not what you want, you should use the following character class: