regex - how to limit, characters between a range using regular expression -
as far know {} curly braces used limit characters in regular expression {3,12}, match character length between 3 12.
i trying validate username might contain period . or _ either one, not both, doesn't matter placement. below regex working well.
(^[a-z0-9]+$)|(^[a-z0-9]*[\.\_][a-z0-9]*$) but need limit string length between 3 12, had tried put {3,12} in regex, doesn't work.
((^[a-z0-9]+$)|(^[a-z0-9]*[\.\_][a-z0-9]*$)){3,12} see example: https://regex101.com/r/kn3ao1/1
as hwnd suggested, simpler solution be:
^(?=.{3,12}$)[a-z0-9]+(?:[._][a-z0-9]+)?$ old solution, rather complex , convoluted,is left here reference, use 1 above instead.
^(?!(?:.{13,}|.{1,2})$)(?:([a-z0-9]+)|([a-z0-9]*[\.\_][a-z0-9]*))$ you can add lookahead this.
Comments
Post a Comment