Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
任何人都知道一个好的正则表达式可以放入 ValidationExpression 以确保我的用户只输入 ASCII 字符?
<asp:RegularExpressionValidator id="myRegex" runat="server" ControlToValidate="txtName" ValidationExpression="???" ErrorMessage="Non-ASCII Characters" Display="Dynamic" />
您可能需要注意的一件事是 ASCII 表的下部有很多控制字符,这可能会导致奇怪的结果。这是我用来只允许“非时髦”字符的表达式:
^([^\x0d\x0a\x20-\x7e\t]*)$
如果要映射可能的 0x00 - 0xff ASCII 值,可以使用此正则表达式 (.NET)。
^([\x00-\xff]*)$