Using said control to validate a ASP.NET TextBox, I’m curious what the most popular practice is. Currently using:
ValidationExpression="^[\w\d\s.,"'-]+$"
Any shorter way of doing this? Tried \ , "" to no avail. Thanks.
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.
Using
\"won’t work, and you won’t be able to use a""either. What you have matches correctly.That said, to make it shorter you could always use the unicode character escape equivalent:
\x22. Even shorter is the octal representation:\42. While both are shorter, they don’t help readability much. Frequent regex users would understand that it represents some character, but they might not know which character without looking it up. In addition, you won’t be able to comment it, unless you plan to leave ASP.NET markup comments nearby to explain the regex.Yet, I don’t particularly like how
"looks like either. It looks odd and out of place, making\x22or\42look a tad cleaner. Your call.Ultimately this lets you shave 2-3 characters off.
EDIT: added an even shorter approach using octal representation.