Using java sprintboot annotation only. For example:
@Pattern(regexp = "(([A-Za-z0-9]+[-. ])*([A-Za-z0-9])){1,30}+")
I need to create a regex validation that will follow these rules:
- maximum value length is between 1-30
- value must start with [A-Za-z0-9]
- in value there can be only one subsequent [-. ]
- value must end with [A-Za-z0-9]
valid values examples:
a
FOO
FOO-A
FOO-A B K.K
NOT valid values examples:
.
A..
X Y
OOPS.
So my final expression was:
(([A-Za-z0-9]+[-. ])*([A-Za-z0-9])){1,30}+
Issue with the above expression is that it counts entire repetitions of all groups and can go pass 30 characters and more.
Is it possible to count total number of characters when it is coming from different groups?