user656925
user656925

Reputation:

Verifying my code uses only ASCI | Checking with regex

IE9 is giving me an error that makes no sense on syntax. missing )

Previously it was Expected ; Previous SO post here

I don't see random errors on any other Browser and my codes passes jslint.com and jshint.com

Want to verify there is no unicode that snuck into my code so I'm going to run it through regex and check for

[\x00-\x7F]

Is this a valid approach?

Related

http://en.wikipedia.org/wiki/ASCII

Upvotes: 0

Views: 125

Answers (1)

some
some

Reputation: 49592

It was almost a decade ago since I developed in IE so my memory might be wrong, but I have a faint recollection that IE didn't like control characters in the code (characters below 0x20, except for line feed, carriage return and tab).

Depending on what editor you use, it is easy to insert control codes by pressing CTRL at the same time as one of @ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_ to get control code 0x00 - 0x1f.

If you want to use a regexp to validate that you only have printable ASCII and allowed control characters you could use ^[\x09\x0a\x0d\x20-\x7e]*$. It allows tab (x09), line feed (x0a), carriage return (x0d) and all printable ASCII characters. Delete (x7f) is left out.

If you want to detect if you have something that isn't a printable ASCII or allowed control character, you can use [^\x09\x0a\x0d\x20-\x7f] to match for anything that isn't tab, line feed, carriage return or printable ASCII.

In Unicode there are some new line terminatos: next line (\u0085), Line Separator (\u2028) and Paragraph Separator (\u2029).

Many internet protocols (and vanilla text files on Windows systems) expect the end of a line to be indicated with carriage return followed by line feed (\0x0d\0x0a), something that is inherited from the days of printers where you wanted to be able to just return the carriage without advancing to the next line, to be able to write underscore for example. It could also be used to make the text a little bolder by printing the same line again, or print in gray scales...

Upvotes: 1

Related Questions