I need to store form data sent from the browser into a database that stores text in Windows-1252. Since modern browsers will send the form data to my backend as UTF-8, I plan to validate the input both on the browser as well as in the backend to make sure I am not storing garbage into the database.
Is there a function in Javascript that checks if a UTF-8 character or string can be converted into Windows-1252 so that I can warn the user that an illegal character was detected before form submission? For example let's say I have a function is_w1252(unicodeChar) that has the following inputs/outputs:
utf8 Input | Output
----------------------------------------------------------
'a' | true
'è' | true (has windows-1252 equivalent: 0xE8)
'fèèbar' | true
'👍' | false (no windows-1252 equivalent)
Is there such a thing?
My PHP backend is much more simple; I plan to use iconv() to convert the form data into Windows-1252 before storing it into the database.