我有一个文本框:
<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." />
Run Code Online (Sandbox Code Playgroud)
我想允许"字符也.我怎么能修改正则表达式字符串???
我试过这个:
<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"
Validat??ionExpression="^[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." />
Run Code Online (Sandbox Code Playgroud)
两次尝试都破坏了字符串.
从您发布的片段中可以看出,正则表达式嵌入在标记中 - 这意味着您需要将双引号字符转义为HTML字符实体.
用途":
ValidationExpression="^[a-zA-Z0-9@+'.!#$'",:;=/\(\),\-\s]{1,255}$"
Run Code Online (Sandbox Code Playgroud)
ASP.NET引擎将字符实体转换为".
或者,ValidationExpression在代码后面设置值(OnInit例如):
ValidateTitleCharacters.ValidationExpression =
"^[a-zA-Z0-9@+'.!#$'\",:;=/\(\),\-\s]{1,255}$";
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6889 次 |
| 最近记录: |