Is there a simple way to check if string is valid UTF-8 sequence in JavaScript?
I really do not want to end with a regular expression like this:
Regex to detect invalid UTF-8 string
P.S.: I am receiving data from external API and sometimes (very rarely but it happens) it returns data with invalid UTF-8 sequences. Trying to put them into PostgreSQL results in an appropriate error.
text.match(/[\x80-\xFF]+/)
to gather potential problems, and checked each match against the UTF-8 specification -- 52 lines of code. Using that regexp is actually a pretty neat, fast, and simple way. - Jongware