# How to validate a date value even if it's nonsense?

**URL:** <https://discuss.workflowgen.com/t/how-to-validate-a-date-value-even-if-its-nonsense/893>\
**Category:** Form Designer\
**Created:** [October 11, 2017, 10:11pm UTC](https://discuss.workflowgen.com/t/how-to-validate-a-date-value-even-if-its-nonsense/893 "2017-10-11T22:11:47Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![esanford](https://avatars.discourse-cdn.com/v4/letter/e/6bbea6/32.png) [@esanford](https://discuss.workflowgen.com/u/esanford)\
**Post date:** [October 11, 2017, 10:11pm UTC](https://discuss.workflowgen.com/t/how-to-validate-a-date-value-even-if-its-nonsense/893/1 "2017-10-11T22:11:47Z")

</div>

I’m trying to validate that an entered value is a date that is \<= today. I was able to do it with a DateTime.Parse() in the Custom OnServerValidate section, but because this validation fires before the form designer’s built-in validation of the date string itself, the .Parse throws an exception in the form if non-date data is entered. DateTime.TryParse() cannot be used there, because it requires more than one line and WFG is injecting the statement into a single if bracket. I even tried writing a method in code behind to handle the logic, but I’m not sure how to call my method from the form designer. I suppose I could create a validator dynamically in code behind, but there must be a simpler way to do this within form designer?

---

<div class="post-metadata">

**Author:** ![eddy.daouk](https://yyz2.discourse-cdn.com/flex030/user_avatar/discuss.workflowgen.com/eddy.daouk/32/672_2.png) [@eddy.daouk](https://discuss.workflowgen.com/u/eddy.daouk)\
**Post date:** [October 18, 2017, 12:02am UTC](https://discuss.workflowgen.com/t/how-to-validate-a-date-value-even-if-its-nonsense/893/2 "2017-10-18T00:02:03Z")

</div>

Hi,

Kindly open a ticket in Helpdesk so we can assist you in solving this issue.

Best Regards,  
Eddy.

---

<div class="post-metadata">

**Author:** ![Rogelio](https://avatars.discourse-cdn.com/v4/letter/r/13edae/32.png) [@Rogelio](https://discuss.workflowgen.com/u/Rogelio)\
**Post date:** [October 27, 2017, 1:31pm UTC](https://discuss.workflowgen.com/t/how-to-validate-a-date-value-even-if-its-nonsense/893/3 "2017-10-27T13:31:33Z")

</div>

> [@esanford](#):
>
> ecause it requires more than one line and WFG is injecting the statement into a single if bracket. I even tried writing a method in code behind to handle the logic, but I’m not sure how to call my method from the form designer. I suppose I could create a validator dynamically in code behind, but there must be a simpler way to do this within form designer?

Hi Eddy,  
I have a similar issue also, just wondering if a solution found? Thank you,  
Rogelio

---

<div class="post-metadata">

**Author:** ![esanford](https://avatars.discourse-cdn.com/v4/letter/e/6bbea6/32.png) [@esanford](https://discuss.workflowgen.com/u/esanford)\
**Post date:** [October 27, 2017, 2:12pm UTC](https://discuss.workflowgen.com/t/how-to-validate-a-date-value-even-if-its-nonsense/893/4 "2017-10-27T14:12:38Z")

</div>

I had to use a custom validator inserted dynamically from cold behind. One disadvantage is that it can’t utilize the popup dialogue that the rest of the form designer validators use, because I couldn’t find a way to integrate it into the form designer specific validator system. So, it I just used display=dynamic and it shows up as red text next to the form field. This is a pretty basic use case that the form designer should be updated to handle.

See here for details: [How to use a .NET CustomValidator control with server-side validation](https://discuss.workflowgen.com/t/how-to-use-a-net-customvalidator-control-with-server-side-validation/194)

---

<div class="post-metadata">

**Author:** ![eddy.daouk](https://yyz2.discourse-cdn.com/flex030/user_avatar/discuss.workflowgen.com/eddy.daouk/32/672_2.png) [@eddy.daouk](https://discuss.workflowgen.com/u/eddy.daouk)\
**Post date:** [October 27, 2017, 2:24pm UTC](https://discuss.workflowgen.com/t/how-to-validate-a-date-value-even-if-its-nonsense/893/5 "2017-10-27T14:24:37Z")

</div>

Hi everyone,

I just tried it and the easiest solution for me was to use another field to do the validation.

Created a simple form and in this case, the Description Textbox validates the DateTime field.

 ![15 AM](https://canada1.discourse-cdn.com/flex030/uploads/workflowgen/original/1X/8b5522c50818e34b3a110240352da04405acef52.png)

Let me know if this meets your needs.

Best Regards,  
Eddy.

---

<div class="post-metadata">

**Author:** ![Rogelio](https://avatars.discourse-cdn.com/v4/letter/r/13edae/32.png) [@Rogelio](https://discuss.workflowgen.com/u/Rogelio)\
**Post date:** [October 27, 2017, 2:38pm UTC](https://discuss.workflowgen.com/t/how-to-validate-a-date-value-even-if-its-nonsense/893/6 "2017-10-27T14:38:34Z")

</div>

Thank you esanford and eddy!
