Field Validations – ASP.NET

Date Text Field Validations

Requirement:Validate entering birth day in a text field with mm/dd/yyyy format.

code in the .aspx or in .ascx



ControlToValidate=”dateOfBirthTextBox” ErrorMessage=”Required”></asp:RequiredFieldValidator>

<asp:RangeValidatorID=”dateOfBirthRangeValidator”runat=”server” ControlToValidate=”dateOfBirthTextBox”

ErrorMessage=”Please enter a past date in mm/dd/yyyy format”  Type=”Date”Display=”Dynamic”></asp:RangeValidator>

code in the .cs file – Under OnInit or PageLoad methods

this.dateOfBirthRangeValidator.MinimumValue = DateTime.MinValue.ToString(“MM/dd/yyyy”);
this.dateOfBirthRangeValidator.MaximumValue = DateTime.Today.ToString(“MM/dd/yyyy”);


Author: Indika Abayarathne

MSc in IT [University of Colombo] Solutions Architect | Consultant Technologies: Power Platform | Dynamics CE | Azure

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: