.net - Regular Expression validator not working in ASP.NET MVC 4 -
i'm new .net , i'm stuck problem want validate password field ,the password must alphanumericstring special symbols , wrote code given below
[required(errormessage = "password required")] [regularexpression(@"^[a-za-z0-9~!@#$%^&*]{8,15}$", errormessage = "password not in proper format")] public virtual string password { get; set; } but not working if password length greater 8 gives green signal string contain alphabets. how can overcome problem
you can use regex
^(?=.*[a-za-z\d])(?=.*[~!@#$%^&*])[a-za-z\d~!@#$%^&*]{8,15}$ ---------------- ----------------- | |->match further if there's 1 of [~!@#$%^&*] |-> match further if there's 1 of [a-za-z0-9]
Comments
Post a Comment