tags:

views:

28

answers:

2

i have got a code to edit some function. There is a text box in that web application. It using a regular expression validator control to validate the text box. the validation expression is

ValidationExpression="[\w]{3,15}"

it accept all letters,numbers and underscores. but it do not accept special characters like \,/ * . i want to change the above regular expression to accept / .

i hope someone can explain what the above regular expression means and how to change that expression to accept / without affecting current regular expression i am using asp.net and c#

+1  A: 
string ValidationExpression= "[\w/]{3,15}"
  • [...] match a single character presents in the list between brackets
  • [...]{3,15} match between 3 and 15 characters presents between brackets
  • \w match a word character (letter, digit, underscore...)
  • / match the character /

So [\w/]{3,15} match a word character or '/' between 3 and 15 times.

madgnome
I think there is no need to give pipe (|) symbol in [] brackets.
Shekhar
@Shekhar, you're totally right. i've updated my answer. Thanks
madgnome
Thank u all foe helping me
Shameer
A: 

Hi, You current regular expression can be deconstructed as follows :

[] brackets represents regular expression group. Regex engine will try to match all the characters or group of characters given inside [] with the input string.

\w - Allow all the alpha numberic characters which includes upper case and lower case alphabets and 0 to 9 numbers and and underscore (This does not include other special characters like / or # ,etc ).

{3,15} means minimum 3 and maximum 15 alphanumeric characters must be provided in order to successfully match the string.

To add other charters, you need to add them explicitly. If you want to add / your regex should be like [\w/]{3,15}.

You can learn everything about regex here.

Shekhar
thank you. one more doubt. if i want to check the size only , what can i do. i tried like this -> ValidationExpression="{3,15}" .But its giving an error
Shameer
got the answer. ValidationExpression=".{3,15}" . thank u again
Shameer
Size of what? input text? If you want to check size / length of input text, then you can just string.length method.
Shekhar
alryt. but i wanted it to do from client side. problem is fixed. thank you
Shameer