Click here to Skip to main content
15,867,756 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want a regular expression to validate date after 17/04/2012 please help me friends
i a have code with regular exp for after 01/01/2012
that is /^(0?[1-9]|[12]\d|3[01])\/(0?[1-9]|1[012])\/(201[2-9]|20[2-9]\d|2[1-9]\d\d)$/
Posted
Updated 28-Jan-14 19:43pm
v2
Comments
MohsenGolmehr 29-Jan-14 0:37am    
Hi Yadagiri Boini.
Can you Use CustomValidator?
Sergey Alexandrovich Kryukov 29-Jan-14 1:24am    
No need. In jQuery, everything is already done; please see Solution 1.
—SA

This is not good to use Regex with every piece of well-structured data, such as date, because this might be already done for you. The better idea is: try to parse data to required structure and see if it succeeds or not. It gives you the really ultimate validation, and, as a big bonus, the structured object itself.

In case of date and Javascript, good thing to use is $.datepicker.parseDate(format, value, settings):
http://api.jqueryui.com/datepicker[^].

You can parse the string to the date format you define yourself. And with this method, you don't have to use the datepicker control itself. However, why not? Using it would be a good idea. If you do it, you may never need to do the parsing per se. :-)

—SA
 
Share this answer
 
v2
Comments
yadagiri boini 29-Jan-14 1:31am    
with out using jquery
Sergey Alexandrovich Kryukov 29-Jan-14 3:32am    
So short comment that it looks rude. And you are cheating — the tag jQuery was there. Besides, jQuery is what you need, so please don't give us unmotivated requirement. Use jQuery.
—SA
this may Help You

C#
protected void CustomValidator13_ServerValidate(object source, ServerValidateEventArgs args)
        {
            DateTime YourDate = DateTime.Now;
            if ( YourDate <= DateTime.Now.AddDays(1))
            {
                args.IsValid = false;
            }
            else
            {
                args.IsValid = true;
            }
        }

C#



in CustomValidator you can use every thing you need but it is Server Side.
 
Share this answer
 
C#
function ddmmyyyy(val)
{
    
    var chkdate = document.getElementById("hiredate").value;
    if(!chkdate.match(/^(0?[1-9]|[12]\d|3[01])\/(0?[5-9]|1[012])\/(2012)|(17|18|19|[2]\d|3[01])\/(04)\/(2012)|(0?[1-9]|[12]\d|3[01])\/(0?[1-9]|1[012])\/(201[3-9]|20[2-9]\d|2[1-9]\d\d)$/))
        {
          $('#err_hire').html('<span style="color:#ff0000">Invalid Date </span>').css('display','block');


        return false;
        }
        else
        {
            $('#err_hire').hide();
            return true;
        }
}
 
Share this answer
 
C#
function ddmmyyyy(val)
{

    var chkdate = document.getElementById("hiredate").value;
    if(!chkdate.match(/^(0?[1-9]|[12]\d|3[01])\/(0?[5-9]|1[012])\/(201[3-9]|20[2-9]\d|2[1-9]\d\d)|(17|18|19|[2]\d|3[01])\/(04)\/(2012)|(0?[1-9]|[12]\d|3[01])\/(0?[5-9]|1[012])\/(201[2-9]|20[2-9]\d|2[1-9]\d\d)$/))
        {
          $('#err_hire').html('<span style="color:#ff0000">Invalid Date </span>').css('display','block');


        return false;
        }
        else
        {
            $('#err_hire').hide();
            return true;
        }
}
 
Share this answer
 

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