Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can i validate a text box so that text box should be filled with the date format mmddyyyy only using a custom validator can any one halp me for doing itthe code using javascript
Posted
Comments
Anuja Pawar Indore 22-Aug-12 9:04am    
Custom validator? Use jquery datetime picker

Something simple as this can't work???

XML
<asp:TextBox ID="txtDate" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ID="regvDate" runat="server" ControlToValidate="txtDate"
    ErrorMessage="Date format is not valid!" ValidationExpression="(0[1-9]|1[012])(0[1-9]|[12][0-9]|3[01])(19|20)\d\d"></asp:RegularExpressionValidator>


Cheers
 
Share this answer
 
Hi ,
Check this
XML
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>

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

<cc1:MaskedEditExtender ID="MaskedEditExtender1" runat="server" Mask="99/99/9999" MaskType="Date" TargetControlID="TextBox1" PromptCharacter="_"> </cc1:MaskedEditExtender>

<cc1:MaskedEditValidator ID="MaskedEditValidator1" runat="server" ControlExtender="MaskedEditExtender1" ControlToValidate="TextBox1" EmptyValueMessage="Date is required" InvalidValueMessage="Date is invalid" IsValidEmpty="False" TooltipMessage="Input a Date"></cc1:MaskedEditValidator>



Best Regards
M.Mitwalli
 
Share this answer
 
Comments
Vani Kulkarni 22-Aug-12 9:07am    
Good answer! My 5!
Mohamed Mitwalli 22-Aug-12 9:08am    
Thank you Vani
__TR__ 22-Aug-12 9:37am    
5+
Mohamed Mitwalli 23-Aug-12 1:01am    
Thank you TR
I do it for one of my application..see it..i wish it will help you..customize it as your wish..
C#
if (!validateInput(autoCompleteBox1.Text, @"^[0-9]\d{1}/[0-9]\d{1}/\d{4}$", "Birthday format isn't correct! Follow day/month/year(ex. 01/01/1990) format.."))
    autoCompleteBox1.Focus();
else
{
  Messagebox.show("Your Birthday saved successfully..");
}

C#
public bool validateInput(string input,string expression,string message)
{
    bool valid = Regex.Match(input,expression).Success;

    if (!valid)
    {
        MessageBox.Show(message, "Invalid Input", MessageBoxButton.OK);
    }
    return valid;
}
 
Share this answer
 
Comments
fjdiewornncalwe 23-Aug-12 14:46pm    
The OP has tagged ASP.Net. Your answer is either WinForms, or you don't understand that the "MessageBox.show" call will result in a dialog being shown on the server and not the client.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900