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

Popular posts from this blog

C# random value from dictionary and tuple -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -

cgi - How do I interpret URLs without extension as files rather than missing directories in nginx? -