(@"^\w+(?: \w+){0,8}$"
the above regular expression restrict all the special characters except _ . how would i restrict it.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Use
to allow everything that
\wmatches except_.\Wmeans “any character that isn’t matched by\w“, so by putting it into a negated character class and adding a_to that class, we’re effectively subtracting_from\w.*In other words,
[^\W_]means “match any character that is neither a non-alphanumeric character nor an underscore”.Another way (perhaps more explicit and easier to understand) would be to use Unicode properties:
where
[\p{L}\p{N}]means “any Unicode letter or number”.*In .NET, the
\wshorthand matches a lot more than[A-Za-z0-9_], especially international (non-ASCII) letters.