Lakshmitha
Lakshmitha

Reputation: 705

how to validate MaskedEditExtender control for MM/dd/yyyy format?

I am using maskedEditExtender control for getting date..

Code inside MaskedEditExtender is

cc1:MaskedEditExtender ID="MaskedEditExtender1" runat="server" TargetControlID="ui_txtRequestDateTime" ClearMaskOnLostFocus="false" Mask="99/99/9999 99:99" UserTimeFormat ="TwentyFourHour">

I need DateTime in MM/dd/yyyy hh:mm formate ,If i use calenderExtender control i can use Format="MM/dd/yyyy" ,but here i couldt specify the format MM/dd/yyyy, its generally "99/99/9999 99:99" format, the 1st two 9's for month, how to tell to user that they have to give month only, if i give value above 12, like 23,24 its showing exception..

Please give some idea..

Upvotes: 0

Views: 3933

Answers (1)

Harun
Harun

Reputation: 5179

Use RegularExpression validator with your textbox as follows:

 <asp:TextBox ID="txtDate" runat="server"></asp:TextBox>

 <asp:RegularExpressionValidator ID="valRegDate" ValidationGroup="OrderAdd"
                        ControlToValidate="txtDate" runat="server" ErrorMessage="Please provide a valid date."
                        ForeColor="Red" ValidationExpression="^(((0?[1-9]|1[012])/(0?[1-9]|1\d|2[0-8])|(0?[13456789]|1[012])/(29|30)|(0?[13578]|1[02])/31)/(19|[2-9]\d)\d{2}|0?2/29/((19|[2-9]\d)(0[48]|[2468][048]|[13579][26])|(([2468][048]|[3579][26])00)))$"></asp:RegularExpressionValidator>      

Upvotes: 1

Related Questions