views:

25

answers:

2

I've been trying to read about and test various regular expression testers to find my solution but to no avial. I'm using:

<asp:RegularExpressionValidator ID="RegularExpressionValidator1" 
ErrorMessage='<%# "*"%>' ValidationExpression="," runat="server"
ControlToValidate="edit_email" Display="Dynamic" 
EnableClientScript="true"></asp:RegularExpressionValidator>

All I want to do is find out if there is a comma in the textbox, which this leads me to believe it would do. I tested this on http://www.regular-expressions.info/javascriptexample.html, as I understand that EnableClientScript="true" means I need to have JavaScript compliant RegEx

Any help would be greatly appreciated, here are the other things I've tried:

  1. ValidationExpression=".*\," Which only hides the error message when I have a string followed by a comma at the end: "123,"
  2. ValidationExpression=".*," Which only hides the error message when I have a string like: "123,"
  3. ValidationExpression="," Which only hides the error message when I have a string like: "," (only one character, and MUST be a comma)
  4. ValidationExpression="[^,]" Which only hides the error message when I have a string like: "1" (only one character, and must NOT be a comma)
  5. ValidationExpression="/,/" Which never hides the error message
+2  A: 

Try this:

ValidationExpression="[^,]*"

That means "zero or more characters, none of which may be a comma"

Dylan Beattie
@Dylan - Thanks, I knew it couldn't be that difficult, but I felt like I was beginning to exhaust everything.
Brett
@Dylan - What if I wanted to do something similar and make sure that my textbox had one instance of "@" but no more than 50 characters, could you advise me on that one?, I was thinking something like "[^@]+.{0,50}"
Brett
+1  A: 

How about .*,.* ? Do you want to know if there is at least one comma or exactly one comma?

CyberDude
@CyberDude - I just want to have a message pop up if there are any commas
Brett
OK then my expression is the opposite of what you need - which is indeed Dylan's
CyberDude