Re: RegExp DoubleQuote

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Thanks very much Jesse.

I played with it for days (and hour here & and hour there) and it was either not working properly or I was receiving errors as I made changes as you suggested. I just stopped looking at it in frustration and left it without the double quotes. To make a long story short, I just went back to it and realized "not working properly" was because in the code I had left out for the allowance of <SPACE> in the "&quot" edition. It had nothing to do with the "&quot". <grrrrr>

It now works great and even though it was an old post, I just wanted to say thanks.


"Jesse Houwing" <jesse.houwing@xxxxxxxxxxxxxxxx> wrote in message news:4AD659F2.5080808@xxxxxxxxxxxxxxxxxxx
* Jennifer Mathews wrote, On 14-10-2009 21:17:
ValidationExpression="[?&\-\[\]\{\}\\#/&gt;&lt;$%!@()':;,._+=0-9a-zA-Z&quot;]+"></asp:RegularExpressionValidator>


WOW!!! Got it to work! Thanks,

But another problem came-up with the following:

ValidationExpression="[?&\-\[\]\{\}\\#/&gt;&lt;$%!@()':;,._+=0-9a-zA-Z&quot;]+{3,50}"
/>
When I put {3,50} for the min and max length, I got the following error:
"parsing "[?&\-\[\]\{\}\\#/><$%!@()':;,._+=0-9a-zA-Z"]+{3,50}" - Nested
quantifier {. "

And length does matter. :)

You've got a +{3,50} in there.

Remove the + and it should start working again.

Jesse



"Jesse Houwing" <jesse.houwing@xxxxxxxxxxxxxxxx> wrote in message
news:eDvJ7jsRKHA.4116@xxxxxxxxxxxxxxxxxxxxxxx
* 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



--
Jesse Houwing
jesse.houwing at sogeti.nl

.



Relevant Pages

  • Re: Correctly Escape Apostroph in URI?
    ... HtmlEncode ... Html mark-up. ... I am already using double quotes as a workaround. ... somewhere to give me a way to correctly escape *any* character I want. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: RegExp DoubleQuote
    ... and recieved an error that the quotes don't match. ... Notice that you officially need to escape the as well when you put them in a tag. ... not work and I recieve an error about it being malformed. ... Jesse Houwing ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: RegExp DoubleQuote
    ... "Jesse Houwing" wrote in message ... and recieved an error that the quotes don't match. ... Notice that you officially need to escape the as well when you put them in a tag. ... Any HTML attribute needs to be escaped according to the rules of the HTML specs. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: A critique of cgi.escape
    ... html and compare it against the expected value. ... unescaped quotes then this change would break it. ... You might sometimes want to escape "right double quote" because it may ... or may not be available in the character encoding you using to output ...
    (comp.lang.python)
  • Re: RegExp DoubleQuote
    ... and recieved an error that the quotes don't match. ... As to why you need to escape the " in this fashion. ... needs to be escaped according to the rules of the HTML specs. ... Jesse Houwing ...
    (microsoft.public.dotnet.languages.csharp)