guys, I don't know this question is already present or not but I have tried every search, so my question is why my regex is not working properly in RegularExpression attribute. this same regex I have used in javascript and this is working on javascript. can anyone help me what I am doing wrong here?
[Required]
[Display(Name = "First name")]
[MaxLength(50)]
[RegularExpression("^(?![@\\+\\-=\\*])", ErrorMessage = "First Name Should not start with these characters @, +, =, *, -")]
public string firstname { get; set; }
I am using this regex for validating the First Name should not start with @,+,=,*,-.
I have already spent 3 hours to figure out what I am doing wrong here.
Your regex is invalid. Here is the updated one, which works as you expected:
I believe you regex should look like this:
Here is a working example.