I need to restrict a string to only allow letters, numbers, hyphens, ampersands, apostrophes and single spaces.
From a bit of searching I've got this so far:
^[A-Za-z0-9-'&\s]{1,}$
But this allows for double spaces. How do I write the regular expression so that it only allows single spaces (there might not be any at all)?
Match any of the other allowed values, followed by an optional single space:
^\s?([A-Za-z0-9-'&]\s?){1,}$
(I also added an optional one at the start, if that's allowed)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With