Re: RegExp DoubleQuote



* Jennifer Mathews wrote, On 6-10-2009 8:50:
Ohhhh ... thanks for the explaination. I thought you were saying
something else.

I just tried your explaination on

ValidationExpression="&quot;[?&\-\[\]\{\}\\#/<>$%!@()':;,._+=
0-9a-zA-Z]+&quot;"

and recieved an error that the quotes don't match.

try:

ValidationExpression="[?&\-\[\]\{\}\\#/&gt;&lt;$%!@()':;,._+=0-9a-zA-Z&quot;]+"

As in the sample code below. I tried running it and it works. Notice that you officially need to escape the < and the > as well when you put them in a tag.

<asp:RegularExpressionValidator ID="ReularExpressionValidator1" runat="server"
ControlToValidate="TextBox1" ErrorMessage="RegularExpressionValidator"

ValidationExpression="[?&\-\[\]\{\}\\#/&gt;&lt;$%!@()':;,._+=0-9a-zA-Z&quot;]+"></asp:RegularExpressionValidator>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" />


I ran it on my local machine and it works.

Notice that the sample expression I posted earlier doesn't match your requirements, but did show you how to add &quot; to the ValidationExpression. The place you added it, doesn't make sense in regards to your previous requirements.

As to why you need to escape the " in this fashion. Any HTML attribute needs to be escaped according to the rules of the HTML specs. And they say that when embedding special characters (like ", <, >) in an attribute, that you need to escape them.

On top of that, you also need to escape certain characters because they have a special meaning in Regex. Just as you'd have to escape them doubly when you put them in source, eg:

ReularExpressionValidator1.ValidationExpression = "[?&\\-\\[\\]\\{\\}\\\\#/<>$%!@()':;,._+=0-9a-zA-Z\"]+";

Or

ReularExpressionValidator1.ValidationExpression = @"[?&\-\[\]\{\}\\#/<>$%!@()':;,._+=0-9a-zA-Z""]+";

Every method has it's own rules.

Jesse




"Jesse Houwing" <jesse.houwing@xxxxxxxxxxxxxxxx> wrote in message
news:O5O8fmdRKHA.4504@xxxxxxxxxxxxxxxxxxxxxxx
* Jennifer Mathews wrote, On 5-10-2009 15:38:
Unfortunately that won't work because it is a regular expression.

Have you actually tried it? If you edit the expression from the
designer it generates &quot; in the expression.

See the following generated code:

<asp:RegularExpressionValidator ID="RegularExpressionValidator1"
runat="server"
ControlToValidate="TextBox1" ErrorMessage="RegularExpressionValidator"

ValidationExpression="&quot;[abab]+&quot;"></asp:RegularExpressionValidator>




"Jesse Houwing" <jesse.houwing@xxxxxxxxxxxxxxxx> wrote in message
news:e132TrTRKHA.4580@xxxxxxxxxxxxxxxxxxxxxxx
* Jeff Johnson wrote, On 4-10-2009 7:16:
"Jennifer Mathews"<waltersjennifer@xxxxxxxx> wrote in message
news:701CCF18-0530-479A-9D15-CA857FB7509B@xxxxxxxxxxxxxxxx

I have a regular expression:
ValidationExpression="[?&\-\[\]\{\}\\#/<>$%!@()':;,._+=
0-9a-zA-Z]{2,60}"

which contains all the characters we need
except DOUBLEQUOTE.

I have tried putting \" (backslash doublequote) into it but that does
not work and I recieve an error about it being malformed.

"Malformed"? Are you doing this on an ASPX page by any chance? I ask
because
I just ran into this problem myself, and it's due to the fact that
ASP.NET
can't handle quotes nested within quotes. I had to create a property
in the
code-behind which did nothing more than return a quote and then
concatenate
it into my target string.



Have you tried &quot; to put in the quotes? That's how they should be
escaped in an HTML tag. I haven't tried this myself in an actual ASPX
page, but it might work.

Jesse

--
Jesse Houwing
jesse.houwing at sogeti.nl



--
Jesse Houwing
jesse.houwing at sogeti.nl



--
Jesse Houwing
jesse.houwing at sogeti.nl
.


Loading