regular expression

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Al Jones

    regular expression

    first time post here.

    I've the following code:

    function validForm(passF orm) {

    << working validation skipped >>

    re = /^\d{5}(-?\d{4})?$/
    validZip = re.exec(passFor m.fldZipCode.va lue)
    if ( !validZip ) {
    alert("Please use either Zip or Zip+4 format");
    passForm.fldZip Code.focus();
    return false;
    }

    << other validation skipped >>
    return true;
    }

    obviously in a validation function. It appears that the execute function is
    returning 'true' from the function as no further validation is being
    performed on the form. I'm at wits end (and being halfwitted it came
    quick). I've checked as much documentation as I can reasonably find. Also
    have run other samples using similar regual expression and for unspecified
    reasons, some seem to work, while others (as this does) just seem to exit
    the .exec and return true. Suggestion??


  • oeyvind toft

    #2
    Re: regular expression

    Try using test instead of exec.

    validZip = re.test(passFor m.fldZipCode.va lue)

    exec returns null if no match is found, test resturns false

    Oeyvind

    --




    "Al Jones" <aljones@yahoo. com> skrev i melding
    news:R5IXc.2336 28$6p.48395@new s.easynews.com. ..[color=blue]
    > first time post here.
    >
    > I've the following code:
    >
    > function validForm(passF orm) {
    >
    > << working validation skipped >>
    >
    > re = /^\d{5}(-?\d{4})?$/
    > validZip = re.exec(passFor m.fldZipCode.va lue)
    > if ( !validZip ) {
    > alert("Please use either Zip or Zip+4 format");
    > passForm.fldZip Code.focus();
    > return false;
    > }
    >
    > << other validation skipped >>
    > return true;
    > }
    >
    > obviously in a validation function. It appears that the execute function[/color]
    is[color=blue]
    > returning 'true' from the function as no further validation is being
    > performed on the form. I'm at wits end (and being halfwitted it came
    > quick). I've checked as much documentation as I can reasonably find.[/color]
    Also[color=blue]
    > have run other samples using similar regual expression and for unspecified
    > reasons, some seem to work, while others (as this does) just seem to exit
    > the .exec and return true. Suggestion??
    >
    >[/color]


    Comment

    Working...