开发者

asp:RegularExpressionValidator, make sure there is no comma in a string

开发者 https://www.devze.com 2023-01-14 19:11 出处:网络
I\'ve been trying to read about and test various regular expression testers to find my solution but to no avial. I\'m using:

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


Try this:

ValidationExpression="[^,]*"

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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号