Regex question

Discussion in 'ASP .Net Building Controls' started by Hailstorm, Aug 20, 2004.

  1. Hailstorm

    Hailstorm Guest

    How can I control if "a textbox is empty or not" with regex validation? I
    don't want to use required field validator because I have a masked textbox
    control and it has "ValidationExpress" property.
    For example, if I want to control if it's a time value, I use
    "(([0-1][0-9])|([2][0-3]))[:]([0-5][0-9])" but it doesn't work when textbox
    is empty. How can I solve this problem? I want user to fill this area.
    And by the way, if I try to use a req field validator for this, my masked
    textbox doesn't seem on validator's "Control To Validate" property although
    it has been inherited from textbox control.


    Waiting for your replies.

    Sincerely
     
    Hailstorm, Aug 20, 2004
    #1
    1. Advertising

  2. I ran into this problem myself -- the validator does not check empty fields
    (see below). I ended up inheriting the validator and changing the
    client-side javascript to include my own validation function. The downside
    is that I had to add that function to a custom WebUIValidation.js (ugh).

    One thing you could do is do the validation on the postback, and then
    trigger the validator (validator.IsValid = false).


    Hope this helps,
    Sam Fields

    excerpt from WebUIValidation.js ...

    function RegularExpressionValidatorEvaluateIsValid(val) {
    var value = ValidatorGetValue(val.controltovalidate);

    #### if length=0 arbitrary "yes" #####
    if (ValidatorTrim(value).length == 0)
    return true;
    var rx = new RegExp(val.validationexpression);
    var matches = rx.exec(value);
    return (matches != null && value == matches[0]);
    }


    "Hailstorm" <nomail@> wrote in message
    news:%...
    > How can I control if "a textbox is empty or not" with regex validation? I
    > don't want to use required field validator because I have a masked textbox
    > control and it has "ValidationExpress" property.
    > For example, if I want to control if it's a time value, I use
    > "(([0-1][0-9])|([2][0-3]))[:]([0-5][0-9])" but it doesn't work when

    textbox
    > is empty. How can I solve this problem? I want user to fill this area.
    > And by the way, if I try to use a req field validator for this, my masked
    > textbox doesn't seem on validator's "Control To Validate" property

    although
    > it has been inherited from textbox control.
    >
    >
    > Waiting for your replies.
    >
    > Sincerely
    >
    >
     
    news.microsoft.com, Aug 20, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?SmViQnVzaGVsbA==?=

    Is ASP Validator Regex Engine Same As VS2003 Find Regex Engine?

    =?Utf-8?B?SmViQnVzaGVsbA==?=, Oct 22, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    712
    =?Utf-8?B?SmViQnVzaGVsbA==?=
    Oct 22, 2005
  2. Rick Venter

    perl regex to java regex

    Rick Venter, Oct 29, 2003, in forum: Java
    Replies:
    5
    Views:
    1,634
    Ant...
    Nov 6, 2003
  3. Replies:
    2
    Views:
    600
  4. Xah Lee
    Replies:
    1
    Views:
    943
    Ilias Lazaridis
    Sep 22, 2006
  5. Replies:
    3
    Views:
    769
    Reedick, Andrew
    Jul 1, 2008
Loading...

Share This Page