How to make a group of regex characters optional? -
i'm trying create regex allows unicode letters, digits, -, , apostrophes first character letter or number, while subsequent characters can letters, numbers, -, or '. think regex works fine except in case user enters single letter or number. there anyway make 2+ characters optional? below current regex:
/^[\p{l}0-9]+[-\'\p{l}0-9']+$/u
thanks!
-eric
without using ?
can use:
/^[\p{l}0-9]+[-\'\p{l}0-9']*$/u
to allow single alpha-numeric in input since [-\'\p{l}0-9']*
means 0 or matches.
Comments
Post a Comment