am trying to implement validations using regex
The validation in aspx page works fine
<asp:RegularExpressionValidator ID="regexEmailValid" display="none" runat="server" ValidationExpression="(([a-z]|[A-Z]|[0-9]|[ ]|[-]|[_]|[@]|[.]|[!]|[$])*)*" ControlToValidate="txtUser" ErrorMessage="Invalid User Name Format"></asp:RegularExpressionValidator>
same one in code behind always returns true
Regex.IsMatch(UserName, "(([a-z]|[A-Z]|[0-9]|[ ]|[-]|[_]|[@]|[.]|[!]|[$])*)*")
tried adding ^ to start but still it always returns true
Regex.IsMatch(UserName, "^(([a-z]|[A-Z]|[0-9]|[ ]|[-]|[_]|[@]|[.]|[!]|[$])*)*")
What am i doing wrong ?
*means zero too so this always match.^[a-zA-Z0-9 _@.!$-]+$