Invisible/Zero-width characters in IE

| By Webner


In Internet Explorer, many times you might have faced issues of invalid date from Date Conversion methods or might have worked with Javascript methods for operations on data. In my case, I used some conversion operation on a date in IE, after that I had to use replace on the date to format it according to my application but the replace method was not working in IE, while all of these were working fine in all other browsers. You might face this type of issue after you have applied date conversion to a variable.

var utcDate= new Date(utcString);

The basic issue in the replace method on a date (that I got from the formatted date object) was, it was appending some invisible characters or non-printable characters and these characters are known as Zero-width characters.

If you debug the running code from the debug console window of IE, copy the date value during debugging the date variable value (using step by step debugging with F10) and paste it on some editor, you will not be able to see that character.

There are different categories of non-printable characters, generally termed as Zero-Width Space, Non-Joiner, Joiner characters and their corresponding Unicode comes in a format as U+200B, U+200C, U+200D, etc.

The trick to check the Zero-Width Characters:

Paste the copied value from IE in the chrome browser console window, but don’t press enter. If you press enter, then the character will not print, so you will not be able to see that character.
When you are able to see character, hover over that character, then you will be able to see the Unicode representation of that character as shown in the screenshot below :
IE characters

In my case, it was appending character with Unicode ‘\u200e’.

var correctDate= myDate.replace(‘\u200e’);

So you can try the above trick to check the character code of the Zero-Width character.

Leave a Reply

Your email address will not be published. Required fields are marked *