I have to provide a data annotation regex for a password that's specified as:
min 8 chars
min 1 upper
min 1 lower
min 1 numeric
min 1 special char which can ONLY be one of the following:$|~=[]'_-+@. (and the password can contain no other special chars besides these)
It's the exclusion of special characters which is giving me the headache.
I've come up with this but it just does not work:
"^.*(?=.{8,})(?=.*[a-z])(?=.*[A-Z])(?=.*[\d])**(?(?!.*[^$|~=[\]'_\-+@.])|([^\W\w])).*$**
It resolves everything I enter as invalid.
Whereas this (for the special chars) on its own does work:
"(?(?!.*[^$|~=[\]'_\-+@.])|([^\W\w])).*$"
and I know the first part works, so what am I missing to make them work together?
Alternatively, is there a much simpler way of achieving this?
(.NET environment)