RegularExpressionValidator set case insensitive for both client and server ValidationExpression

J

J055

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
 
W

Walter Wang [MSFT]

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 ([email protected], 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.
 
J

J055

Hi Walter

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

Thanks
Andrew
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top