Inconsistant Regular Expressions

Last post 07-31-2007 10:54 PM by angryllama. 2 replies.

Sort Posts:

  • Inconsistant Regular Expressions

    07-16-2007, 12:02 PM
    • Loading...
    • angryllama
    • Joined on 02-21-2007, 12:38 PM
    • Posts 11

    I am having trouble with inconsistant behavior regarding regular expressions.

    I use the following regexp to test for a 'strong' password: ^(?=.*[0-9]).{6,20}$

     This requires 6-20 characters with at least one digit.  The expression works PERFECTLY when I use it with System.Text.RegularExpressions' Regex.IsMatch() function.  However, the expression is ALWAY invalid when used with the RegularExpressionValidator control.  What is going on? This is a very standard regular expression.  Also, I know that R.E.Validator doesn't require the $ and ^ anchors, but the validation still doesn't work when I remove the anchors.

     Any help will be appreciated.

     -Paul

  • Re: Inconsistant Regular Expressions

    07-16-2007, 2:13 PM
    Answer
    • Loading...
    • RichardD
    • Joined on 09-03-2002, 11:43 AM
    • Sussex, UK
    • Posts 91

    Javascript regular expressions don't support look-ahead constructs, so you'll need to turn off client script for the validator (EnableClientScript="false"). You'll also need to add a RequiredFieldValidator, since the RegularExpressionValidator ignores empty values.

  • Re: Inconsistant Regular Expressions

    07-31-2007, 10:54 PM
    • Loading...
    • angryllama
    • Joined on 02-21-2007, 12:38 PM
    • Posts 11

    Ah, I see.  I figured it was something about .NET vs. JavaScript..  didn't know Java doesn't support Look-aheads.  I knew about the RequiredFieldValidator though, but didn't mention it in order to simplify the example.

     

    Thanks

     

Page 1 of 1 (3 items)