2

I had an issue with IE parsing a date , took me two hours that the date I was actually parsing has hidden characters within.

Disregarding the parse issue , I just want to know what on earth are these ?

alert("‎3‎/‎9‎/‎2016"==="3/9/2016")
alert("‎3‎/‎9‎/‎2016")
alert("3/9/2016")

JsFiddle

If no one has explaination , How can I trim these weird characters to get a valid string ?

ProllyGeek
  • 15,517
  • 9
  • 53
  • 72

4 Answers4

6

It seems like it's this: http://www.fileformat.info/info/unicode/char/200e/index.htm

I did: "‎3‎/‎9‎/‎2016".charCodeAt(0) and then googled the result.

Just replace everything that's not what you expect. In this case, it seems like you only want numbers or slashes. So ignoring every else would be /[^\d\/]. So this works:

"‎3‎/‎9‎/‎2016".replace(/[^\d\/]/g, '') === '3/9/2016'
Jack
  • 20,735
  • 11
  • 48
  • 48
2

These are left-to-right marks. Unicode uE2808E.

deamentiaemundi
  • 5,502
  • 2
  • 12
  • 20
2

Using charCodeAt I figured that the symbol was char code 8026. I was then able to find another answer that should help explain your issue. Here's a relevant part of that answer.

You are likely getting the LTR markers because your display locale is RTL. Besides this, consider that the locale will always affect the output. Perhaps your locale uses dd/mm/yyyy formatting instead of mm/dd/yyyy formatting. Or perhaps your locale requires Asian or Arabic characters. These are all considerations when determining a display format, but are never appropriate for machine parsing.

tl;dr: the issue arises from getting output that is based on the machine's locale, something IE takes into account. If the locale displays RTL, IE outputs LTR, or it's some weird support for an Asian or Arabic language.

None-the-less, the aforementioned answer should be all the info you need: don't expect locale-formatted text to be machine-usable, they're meant only to be human-readable. Sure, you could filter out the characters, but there's always the possibility you could run into another locale.

Community
  • 1
  • 1
Clavin
  • 1,182
  • 8
  • 17
2

(Just for completeness; obviously this won't fit in a comment.)

➜  ~ hexdump -C tmp.js
00000000  61 6c 65 72 74 28 22 e2  80 8e 33 e2 80 8e 2f e2  |alert("...3.../.|
00000010  80 8e 39 e2 80 8e 2f e2  80 8e 32 30 31 36 22 29  |..9.../...2016")|
00000020  0a 61 6c 65 72 74 28 22  33 2f 39 2f 32 30 31 36  |.alert("3/9/2016|
00000030  22 29 0a                                          |").|
Dave Newton
  • 158,873
  • 26
  • 254
  • 302