.Net Regex ValidationExpression ASCII

让人想犯罪 __ 提交于 2020-01-23 20:30:28

问题


Anyone know a good Regex expression to drop in the ValidationExpression to be sure that my users are only entering ASCII characters?

<asp:RegularExpressionValidator id="myRegex" runat="server" ControlToValidate="txtName" ValidationExpression="???" ErrorMessage="Non-ASCII Characters" Display="Dynamic" />

回答1:


One thing you may want to watch out for is the lower part of the ascii table has a lot of control characters which can cause funky results. Here's the expression I use to only allow "non-funky" characters:

^([^\x0d\x0a\x20-\x7e\t]*)$




回答2:


If you want to map the possible 0x00 - 0xff ASCII values you can use this regular expression (.NET).

^([\x00-\xff]*)$


来源:https://stackoverflow.com/questions/150901/net-regex-validationexpression-ascii

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