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

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

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