For name validation using the Regex, I need to have the below requirements.
- Can include letters, spaces, apostrophe(') and hyphen(-) only
- multiple spaces are allowed between the characters (example: " asd asd asd asd ")
- Cannot have spaces before or after hyphen(-) (example: "abc-abc" is allowed, "abc -abc" and "abc- abc" is not allowed)
I'm currently using this Regex:
(^[a-zA-Z' ]+(?:[- ][a-zA-Z']+)*$
This regex meets every requirement except the fact that it's allowing spaces before hyphen.
How can I disallow spaces before hyphen meeting every other requirement too here?