tmjam
tmjam

Reputation: 1039

How to add en-dash and em-dash in a regular expression

I want to add client side regex validation to inlcude en-dash(–) and em-dash(—)

<asp:RegularExpressionValidator ID="NameRegExValidator" runat="server" ValidationExpression="[a-zA-Z\d.,!&/\(\)#\$?£àÀâÂäÄáÁéÉèÈêÊëËìÌîÎïÏòÒôÔöÖùÙûÛüÜçÇ’ñ€\|%\^\*@`~\+;:\-'\s\\&quot;]+" ErrorMessage="Illegal Characters" ControlToValidate="Name" ></asp:RegularExpressionValidator>

can anyone help me out ?

Upvotes: 2

Views: 2366

Answers (1)

user557597
user557597

Reputation:

I'm not a .net expert, but couldn't you just put the characters in the class?
Or put the codepoint in the class, or thier char references (xhtml/xml).

en dash – U+2013 &ndash; &#x2013; or &#8211;  
em dash — U+2014 &mdash; &#x2014; or &#8212;   

[a-zA-Z\d.,!&/\(\)#\$?£àÀâÂäÄáÁéÉèÈêÊëËìÌîÎïÏòÒôÔöÖùÙûÛüÜçÇ’ñ€\|%\^\*@`~\+;:\-'\s\\&quot;&#x2013;&#x2014;]+ 

[a-zA-Z\d.,!&/()#\$?£àÀâÂäÄáÁéÉèÈêÊëËìÌîÎïÏòÒôÔöÖùÙûÛüÜçÇ’ñ€\|%\^*@`~+;:-'\s\"–—]+

Upvotes: 1

Related Questions