0

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#

2 Answers 2

2
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.

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

2 Comments

I think there is no need to give pipe (|) symbol in [] brackets.
@Shekhar, you're totally right. i've updated my answer. Thanks
0

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.

4 Comments

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
got the answer. ValidationExpression=".{3,15}" . thank u again
Size of what? input text? If you want to check size / length of input text, then you can just string.length method.
alryt. but i wanted it to do from client side. problem is fixed. thank you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.