1

I have asp.net RegularExpressionValidator
ValidationExpression="^[a-zA-Z\?*.\?!\@#\%\&\~`\$\^_\,()\//]{1,30}$" /> It will support any alpha numeric charectors excepts script tags. right now it wont supports any other language except english.

I want modify this regular expression to support arabic charectors also. Please help me how to modify this expression..

Thanks in advance..

1
  • It would help if you told us what you are trying to "validate". Commented May 24, 2012 at 16:10

2 Answers 2

1

You essentially need to change your regex from a whitelist to a blacklist. So you want to check for characters that you don't want to allow. You can achieve this by starting your regex with a ^ inside the opening bracket. So

ValidationExpression="[^\?*.\?!\@#\%\&\~`\$\^_\,()\//]" 

will pass any string that does not contain the characters in the expression.

Sign up to request clarification or add additional context in comments.

2 Comments

I do not recommend using blacklists; they are fail-unsafe. If anything goes wrong or changes, or if your characters are ever mapped, translated, bit-stripped, or a thousand other things happen, blacklists allow invalid characters. Stick with whitelists, they are fail-safe. If a whitelist breaks it will forbid a valid character, which is annoying but not a security vulnerability.
I want to add limit the number of charector it will accept say for example it should accept only 200 charectors, since it is a asp.net TextBox(multiline)
0

You can add Arabic characters to regular expressions; they match themselves. One problem with Unicode is that Arabic digits, punctuation, and ornaments are scattered around in code blocks, so you may have to add specific symbols you are looking for:

ValidationExpression="^[a-zA-Z\?*.\?!\@#\%\&\~`\$\^_\,()\//\u0621-\u063F\u066E-\u06D3]{1,30}$" 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.