* 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=""[?&\-\[\]\{\}\\#/<>$%!@()':;,._+=
0-9a-zA-Z]+""
and recieved an error that the quotes don't match.
try:
ValidationExpression="[?&\-\[\]\{\}\\#/><$%!@()':;,._+=0-9a-zA-Z"]+"
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="[?&\-\[\]\{\}\\#/><$%!@()':;,._+=0-9a-zA-Z"]+"></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 " 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
* 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 " in the expression.
See the following generated code:
<asp:RegularExpressionValidator ID="RegularExpressionValidator1"
runat="server"
ControlToValidate="TextBox1" ErrorMessage="RegularExpressionValidator"
ValidationExpression=""[abab]+""></asp:RegularExpressionValidator>
* Jeff Johnson wrote, On 4-10-2009 7:16:
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 " 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