I have a textbox :
<asp:RegularExpressionValidator ID="ValidateTitleCharacters" runat="server"
ValidationExpression="^[a-zA-Z0-9@+'.!#$',:;=/\(\),\-\s]{1,255}$"
ControlToValidate="title" Text="You have entered a character(s) that is not allowed in the title."
ErrorMessage="You have entered a character(s) that is not allowed in the title." />
I want to allow ” character also. How can I modify the regular expression string???
I tried this:
<asp:RegularExpressionValidator ID="ValidateTitleCharacters" runat="server"
ValidationExpression="^[a-zA-Z0-9@+'.!#$'\",:;=/(),\-\s]{1,255}$"
ControlToValidate="title" Text="You have entered a character(s) that is not allowed in the title."
ErrorMessage="You have entered a character(s) that is not allowed in the title." />
<asp:RegularExpressionValidator ID="ValidateTitleCharacters" runat="server"
ValidationExpression="^[a-zA-Z0-9@+'.!#$',:;=/()(""),\-\s]{1,255}$"
ControlToValidate="title" Text="You have entered a character(s) that is not allowed in the title."
ErrorMessage="You have entered a character(s) that is not allowed in the title." />
Both attempts are breaking the string.
From the fragment you have posted, it appears that the regular expression is embedded in markup – this means you need to escape the double quote character as an HTML character entity.
Use
":The ASP.NET engine will translate the character entity to
".Alternatively, set the
ValidationExpressionvalue in code behind (inOnInit, for example):