RegularExpressionValidator set case insensitive for both client and server ValidationExpression

Discussion in 'ASP .Net' started by J055, Nov 19, 2007.

  1. J055

    J055 Guest


    I've having trouble getting this expression to work in both javascript and
    server side.


    I'd like to apply a ValidationExpression which is case insensitive and works
    in both client and .NET.

    Is this possible?
    J055, Nov 19, 2007
    1. Advertisements

  2. Hi Andrew,

    When using RegularExpressionValidator, if the client-side javascript is
    enabled and you enabled EnableClientScript, the regular-expression
    validation occurs both client-side and server-side. However, the validation
    implementation is slightly different on the client than on the server. On
    the client, JScript regular-expression syntax is used. On the server,
    System.Text.RegularExpressions.Regex syntax is used. Since JScript regular
    expression syntax is a subset of System.Text.RegularExpressions.Regex
    syntax, it's recommended that JScript regular-expression syntax be used in
    order to yield the same results on both the client and the server.

    Some changes to your regular exression:

    1) The validation is alreay trying to match the whole expression,
    therefore you don't need to specify ^ and $.
    2) The regular expression options are all turned off by default, therefore
    you don't need to specify "-msnx".
    3) For the "ignore case" option, since .NET and JScript uses different
    approach to specify this option, we have to use other workaround.

    I've tested following regex and it works both client side and server side.


    Hope this helps.

    Walter Wang (, remove 'online.')
    Microsoft Online Community Support

    When responding to posts, please "Reply to Group" via your newsreader so
    that others may learn and benefit from your issue.

    This posting is provided "AS IS" with no warranties, and confers no rights.
    Walter Wang [MSFT], Nov 20, 2007
    1. Advertisements

  3. J055

    J055 Guest

    Hi Walter

    That's great. It makes the expression a little long winded but it works for
    my requirements.

    J055, Nov 21, 2007
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.