Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a Model what contains a column "Confirmed" and "Details".

"Confirmed" can have a entry like "2024-01-11 21:10:42" or "NA". It should be valid if it has a DateTime and not valid by "NA".
"Details" can have "Delta", "Delta - ORT PAM", "Delta - Strasse_HNR2 PAM" or "ok". There it should be invalid, if it has "ok".

So all "NA" and "ok" can be removed before mapping to target model.

Sadly i'm getting that data from external in that form.

Is it possible to made rules for Fluent Validator for that?

What I have tried:

Read docs. But don't found anything that matches my needs. I just found "Otherwise" but as far i understand, i just have two possible checks.
Posted
Updated 19-Jan-24 21:03pm
v4
Comments
Dave Kreskowiak 19-Jan-24 18:45pm    
Your first mistake, and it's a big one, is storing datetime values as strings. Your Confirmed column should be storing datetime values as DateTime types, which can also be null, not "NA".
Sascha Manns 20-Jan-24 2:49am    
Thats true. In that case i'm getting that from external and they writing a Date or "NA" in that field. They generating that information automatically.
Dave Kreskowiak 20-Jan-24 10:51am    
Weird but OK. You can always use the .Must validator and supply your own custom code for converting the datetime string into an actual DateTime value. If that conversion fails, you move on to checking it for "NA", and if that fails, return false. If either condition works, return true.
Sascha Manns 21-Jan-24 5:32am    
Indeed it's weird. I think your idea is the best solution for this issue.
Graeme_Grant 20-Jan-24 3:01am    
Update your question with sample code that you have tried. Use the green "improve question" link.

To be quite frank,there is more than enough information in the links provided for you to complete your task.

However, if you are expecting someone to write the code for you, without any attempt, then I recommend these websites:
* fiverr[^]
* Upwork[^]
* Freelancer[^]
* Guru[^]
* PeoplePerHour[^]
* TaskRabbit[^]
* Karat[^]

Here is the official documentation: Built-in Validators — FluentValidation documentation[^] - has examples for each. Then for compound checks: Dependent Rules — FluentValidation documentation[^] - again with a sample.
 
Share this answer
 
Sometimes you can't come up with the simplest solutions. I don't have to validate every piece of information. In my case it is enough to exclude "ok" and "NA". That's enough to use .NotEmpty().NotEqual("ok") and .NotEmpty().NotEqual("NA").
 
Share this answer
 

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