Devexpress textbox regular expression validator not validating correctly

只谈情不闲聊 提交于 2019-12-25 02:26:25

问题


For some reasons, I have to use devexpress textbox instead of asp textbox, and the textbox have a validation that the text must contain a ".", so I am using regular expression to validate the user's input like below:

<dx:ASPxTextBox runat="server" ID="textBox1"  ValidationSettings-ValidationGroup='<%# Container.ValidationGroup %>'>
                                                            <ValidationSettings>
                                                                <RegularExpression ValidationExpression="[.]" ErrorText="Invalid input" />
                                                            </ValidationSettings>
                                                        </dx:ASPxTextBox>

I.e. the regex is very simple, just [.]

I tested the regex on this site http://regexpal.com/ and it's validating properly, but when it's put inside the aspxTextbox, whenever the user type in anything that contains ".", the validation isn't passed (i.e. error text shows), why this happens?


回答1:


Just try the below regex to make your validation getting passed.

^.*\..*$

Explanation:

  • ^ - Asserts that we are at the start. For validation purposes, we must give the start and end patterns.
  • .* - Matches any character zero or more times.
  • \. - Matches a literal dot.
  • .* - Matches any character zero or more times.
  • $ - End of the line.


来源:https://stackoverflow.com/questions/24671303/devexpress-textbox-regular-expression-validator-not-validating-correctly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!