Question

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" />
Was it helpful?

Solution

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]*)$

OTHER TIPS

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

^([\x00-\xff]*)$
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top