question

eddy28-8301 avatar image
0 Votes"
eddy28-8301 asked DuaneArnold-0443 commented

Regular Expression error message

Hello,

I wanted to include a regular expression to detail the parameters for a password, but I wanted to include an error message in order to see which parameters are fulfilled or not. Ive tried multiple regular expressions but that is illegal. How would I be able to implement this without complicating it further and creating a new class etc.

This is my code for the regular expression: [RegularExpression(@"^(?=.*[a-z])|(?=.*[A-Z])|(?=.*\d)|(?=.*[^a-zA-Z\d])$", ErrorMessage = "Password should have atleast one lowercase | atleast one uppercase, should have atleast one number, should have atleast one special character")]

while I want it to look similar to this:

103718-password.png

Where it updates whichever parameters are missing or fulfilled, how would I be able to do this the most effective way?
Thanks!


dotnet-aspnet-core-generaldotnet-aspnet-core-mvc
password.png (77.3 KiB)
· 6
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

You trying to create your own registration page?

0 Votes 0 ·

yes. I am

0 Votes 0 ·

Hi,@eddy28-8301,

What about using custom-attributes?You can check the password in IsValid method,and return the error message you want in ValidationResult.

0 Votes 0 ·
Show more comments

You can also do a series of regular expression code in the controller and put errors in the ModelStare collection too that will make the
ModelState invalid. Just return the view using Validationhelper in the view. If you use data annotations, you can have more than one attribute for a property, if you have read my other reply. :)


0 Votes 0 ·

0 Answers