Reputation: 7707
I am using VB.net as well as Jquery Datepicker for getting dates.
In my VB.net code
<tr>
<td>
DateOfReceiving:
</td>
<td colspan="3">
<asp:TextBox ID="DateOfReceivingTextBox" runat="server"
CssClass="pastdatepicker"
Text="DateOfReceiving" />
</td>
</tr>
I want to allow enter user only todays date or past date with format dd/mm/yyyy
. I want vb.net custom validation for that.
Please help to write vb.net regular expression.
Upvotes: 1
Views: 2070
Reputation: 12589
You can do this with a RangeValidator and a bit of VB.NET code:
<tr>
<td>DateOfReceiving:</td>
<td colspan="3">
<asp:TextBox ID="DateOfReceivingTextBox" runat="server"
CssClass="pastdatepicker"
Text="DateOfReceiving" />
<asp:rangevalidator runat="server" ID="DateRangeValidator"
ControlToValidate="DateofReceivingTextBox"
ErrorMessage="Date must be in the past"
Display="Dynamic" Type="Date" />
</td>
</tr>
Set the range for the validator in your code-behind, most likely in your Page_Load:
DateRangeValidator.MinimumValue = Date.MinValue.ToString("yyyy/MM/dd")
DateRangeValidator.MaximumValue = Date.Today.ToString("yyyy/MM/dd")
Upvotes: 3
Reputation: 116187
You aren't going to want to use a regular expression for this.
If you want to do this server-side, you should look into creating validation controls. I've never done this in VB.NET (simply because I've never used VB.NET - I'm more comfortable with C#), but this page appears to be a good starting point. You are going to want to inherit from and override methods in the BaseValidator
class.
I don't usually write client-side code unless I have to, but it looks like jQuery supports form validation as well. However, as brad.huffman pointed out in the comments, you probably want to avoid doing date/time validation on the client side as you can't control your user's date/time settings - they could be incorrect.
Upvotes: 1