Suggestion RegExpValidator with regexp options

Last post 01-24-2007 1:51 PM by PLBlum. 1 replies.

Sort Posts:

  • Suggestion RegExpValidator with regexp options

    01-24-2007, 10:50 AM
    • Loading...
    • pnmcosta
    • Joined on 10-06-2006, 6:44 PM
    • Posts 58

    Hya,

    I've searched all over the net and couldn't find any workaround for this, but this is my problem i have a data validation regex "^((31(?!\ (Feb(ruary)?|Apr(il)?|June?|(Sep(?=\b|t)t?|Nov)(ember)?)))|((30|29)(?!\ Feb(ruary)?))|(29(?=\ Feb(ruary)?\ (((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)))))|(0?[1-9])|1\d|2[0-8])\ (Jan(uary)?|Feb(ruary)?|Ma(r(ch)?|y)|Apr(il)?|Ju((ly?)|(ne?))|Aug(ust)?|Oct(ober)?|(Sep(?=\b|t)t?|Nov|Dec)(ember)?)\ ((1[6-9]|[2-9]\d)\d{2})$"

     
    This validates a valid date of dd MMM yyyy format the only problem i have is that if the user inputs feb or jan instead of Feb and Jan, it will not validate.

    I may not be doing it on the right forum, but please do guide me. I would like to suggest an update to the regularexpressionvalidator to implement regex options such as IgnoreCase, i've tried adding /i at the end of the expression like with javascript but it doesn't work..

    regards,

    P.


     

  • Re: Suggestion RegExpValidator with regexp options

    01-24-2007, 1:51 PM
    Answer
    • Loading...
    • PLBlum
    • Joined on 06-28-2002, 9:20 AM
    • Boston, MA
    • Posts 5,155

    One of the challenges to validating dates is to make sure the user enters a real date, not just one that has the legal elements. (Legal but not real: 31 Feb 2007).

    Because you are getting into very complex regular expressions that still don't address the issue of illegal dates, consider another approach. Here are a couple:

    1. Use the CustomValidator and only implement the server side validation for this control. Its very easy to use .net's DateTime object to validate the date.

    try
    {
       var DateTime = DateTime.ParseExact(args.Value, "dd MMM yyyy", null);
       args.IsValid = true;
    }
    catch (Exception)
    {
       args.IsValid = false;
    }

    2. There are some third party DatePickers (datetextboxes with popup calendars) that offer both the formatting you need, and associated validators that support the format. I'm the author of one, "Peter's Date Package". For others, see this site's Control Gallery (under Resources), www.123aspx.com, and www.411asp.net.

    --- Peter Blum
    Creator of Peter's Data Entry Suite (formerly Professional Validation And More and Peter's Date Package) and Peter's Polling Package
    www.PeterBlum.com
Page 1 of 1 (2 items)
Microsoft Communities
Page view counter