# Date Validation

## Content



ComponentOne MVC Edition's **InputDate** control has a built-in validator, **ItemValidator** that lets you control the type of data or the value that users select from the InputDate drop down. All you need to do is create a validation function, which is assigned to ItemValidator to allow or restrict the selection of dates by the user.

In this example, ItemValidator is created so that a user can select a weekday, but not Saturdays and Sundays i.e. in the InputDate control. This kind of validation is useful while planning your work sprints, workout days or diet plan.

The following images show how the **InputDate** control appears after applying ItemValidator function to it.

![](https://cdn.mescius.io/document-site-files/images/9b6a6cfe-b8e8-42e9-8a04-da6cb7762977/images/inputdatevalidate.png)

The following code examples demonstrate how to add ItemValidator in the InputDate control:

#### In Code

**Add a new Controller**:

1.  In the **Solution Explorer**, right click the folder **Controllers.**
2.  From the context menu, select **Add | Controller**. The **Add Scaffold** dialog appears.
3.  Complete the following steps in the **Add Scaffold** dialog:
    1.  Select **Empty MVC Controller** template.
    2.  Set name of the controller (for example: `Default1Controller`).
    3.  Click **Add**.
4.  A new controller is added to the application.

**InputDate.cshtml**

```html
@{
    var today = DateTime.Now.Date;
    var minDate = new DateTime(today.Year, 1, 1);
    var maxDate = new DateTime(today.Year, 12, 31);
}
<script>
    function itemValidator(date) {
        var weekday = date.getDay();
        return weekday != 0 && weekday != 6;
    }
</script>
<div>
    <c1-input-date value="@today" min="@minDate" max="@maxDate" item-validator="itemValidator">
    </c1-input-date>
</div>
```