Search code examples
regexinputcharacterapostropheletters

Regex to allow apostrophe only for words ending with s


I'm using this Regex ^[a-zA-Z0-9]{2,20}$ to allow the following rules: - Letters a-z - Letters A-Z - Numbers 0-9 - Input length must be at least 2 characters and maximum 20 characters.

I also want to allow apostrophe only at the end of words ending with s.

Thanks,


Solution

  • ^([a-zA-Z0-9]{2,20}|[a-zA-Z0-9]{2,18}'s)$
    

    So: either your original regex, or your original regex (reduced to maximum 18 characters, you might want to change the minimum as well) ending in "'s".