I am trying to put together a regex pattern to validate usernames in our account creation PS script. The format of our usernames are FirstName.LastName. We do accept hyphens,apostrophes and numbers also but only as follows:
Firstname - letters only, hyphens, apostrophes also accepted.
LastName - alphanumeric accepted, hyphens and apostrophes also accepted.
The below regex seems to work but it doesn't work for if the username begins or ends with an apostrophe/hyphen as they are valid characters.
"^[a-zA-Z]+-*'*[a-zA-Z]+\.[a-zA-Z]+-*'*[0-9a-zA-Z]+$"
How would i amend the above to also ensure the string doesn't match if it begins or ends with an apostrophe or hyphen? i'd also like to limit hyphens and apostrophes to only 1 consecutive (E.g. "sh-aun" and not "sha--un, "sh'aun" and not "sh''aun") in both the firstname part and lastname part.
Any help would be much appreciated. Thanks in advance.