The number is different from itself (trimming strange characters)

I copied the first number from the Windows calculator and dialed the second. In the Chrome console, I get:

"‭65033‬" == "65033"
//false

65033‬ == 65033
//Uncaught SyntaxError: Invalid or unexpected token

It seems that at the beginning and at the end there is an unknown character.

1) Is there a way to cut off all the “weird” characters without knowing them a priori?

2) Why does the window calculator put such characters in a number?

Edit: It was not explicit in the question, but any characters with reliable information, such as ã, ü, ç, ¢, £, would also be valid. What I do not want are characters that do not contain any information for the reader.

+4
source share
2 answers

A quick fix for this case:

eval("65033‬ == 65033".replace(/[^a-zA-Z0-9 =-_.]/, ''))

, ( , ).

- + , , , .. - , , .

, .

, . , .

0

: , .

var myNumber = 'foo123bar';
var realNumber = window.parseInt(myNumber.replace(/\D*/g, ''), 10);

?

, , .

+1

Source: https://habr.com/ru/post/1667878/


All Articles