Click here to Skip to main content
15,886,872 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Model class:
C#
[RegularExpression(@"^(?=*[A-Z])(?=*[a-z])(?=*[0-9])[A-Za-z0-9]{8,}$", ErrorMessage = "invalid")]
       [Required(ErrorMessage = "Required")]
       [StringLength(65)]
       [Display(Name = "Password")]
      // [RegularExpression(@"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{8,}$", ErrorMessage = "Password contains invalid characters")]
       //[DataType(DataType.Password)]
       public string password { get; set; }


Login Action method:
C#
public ActionResult Login(Login loginForm, string returnUrl)
       {
           if (!ModelState.IsValid) return View("Login");
           var Password = Md5Hash.Encrypt(loginForm.Password);

           var user = (from users in _dbContextModel.user_login
                       where ((users.login_id == loginForm.Login_id) && (users.password == Password))
                       select users).FirstOrDefault();

           if (user != null)
           {
               UserLogin userLogin = user;
               userLogin.last_login = DateTime.Now;

              // userLogin.password = user.password;

               _dbContextModel.Entry(userLogin).State = EntityState.Modified;
               _dbContextModel.SaveChanges();


When i am using above regular expression, i am facing the following run-time exception why? please give me solution. I am using linq, E.F7 and MVC5 using VS015 and .net framework 4.5

My ERROR IS:
Validation failed one or more entity

What I have tried:

google google google google google google google google google google google google google google google google google
Posted
Updated 30-Jul-16 16:40pm
v3
Comments
PIEBALDconsult 30-Jul-16 15:10pm    
Might help if you provided the imput value for us to see, and what you think the regex is supposed to do.
Aijaz Ali Abro 30-Jul-16 15:17pm    
yes it is working fine without hashing

1 solution

At best, your RegEx
^(?=*[A-Z])(?=*[a-z])(?=*[0-9])[A-Za-z0-9]{8,}$

is weird, ?=* look meaningless. Are you sure it is valid ?

Can you explain what it is supposed to validate?
 
Share this answer
 
Comments
Aijaz Ali Abro 31-Jul-16 3:37am    
i have removed <pre>?=*</per> but still getting same error
Patrice T 31-Jul-16 3:40am    
Tell what the regex is supposed to validate.
the format of validation.
Aijaz Ali Abro 31-Jul-16 4:46am    
i am using this regular expression : [RegularExpression(@"^(?=*[A-Z])(?=*[a-z])(?=*[0-9])[A-Za-z0-9]{8,}$", ErrorMessage = "invalid")]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900