RegularExpressionValidator set case insensitive for both client and server ValidationExpression

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

  1. J055

    J055 Guest

    Hi

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

    (?:^.+\.)(?i-msnx:((jpg)|(gif)))$

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

    Is this possible?
    Thanks
    Andrew
     
    J055, Nov 19, 2007
    #1
    1. Advertising

  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.


    .+\.([jJ][pP][gG]|[gG][iI][fF])


    Hope this helps.


    Regards,
    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
    #2
    1. Advertising

  3. J055

    J055 Guest

    Hi Walter

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

    Thanks
    Andrew
     
    J055, Nov 21, 2007
    #3
    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. Tee
    Replies:
    3
    Views:
    7,817
    Herfried K. Wagner [MVP]
    Jun 23, 2004
  2. Morten71
    Replies:
    0
    Views:
    634
    Morten71
    Apr 2, 2007
  3. Replies:
    1
    Views:
    2,485
    Mark P
    Apr 6, 2007
  4. Andy Eshtry
    Replies:
    0
    Views:
    352
    Andy Eshtry
    Jun 29, 2004
  5. Xah Lee
    Replies:
    4
    Views:
    984
Loading...

Share This Page