javascript - ANSI vs UTF-8 in web Browser -


my requirement allow users use(type) ansi characters instead of utf-8 when typing in text fields of webpages.

i looked @ setting of character set in html meta tag

 <meta charset="iso-8859-1">  

that helpful display content in ansi instead of utf-8, not stop users typing in utf-8. appreciated.

let's distinguish between 2 things here: characters user can type , encoding used send data server. these 2 separate issues.

a user can type want form in browser. intents , purposes these characters have no encoding @ point, they're pure "text"; encodings not play role yet , cannot restrict set of available characters encodings.

once user submits form, browser have encode data binary somehow, encoding comes in. browser decides how encode data, choose encoding specified in http headers, meta elements and/or accept-charset attribute of form. latter should deciding factor, you'll find buggy behaviour in real world (*cough*cough*ie*cough*). in practice, 3 character set definitions should identical not cause confusion there.

now, if user typed in "exotic" characters , browser has decided encode data in "ansi" , chosen encoding cannot represent exotic characters, browser typically replace characters html entities. so, in case doesn't restrict allowed characters, finds different way encode them.

how can know encoding used user

you cannot. can specify character set like receive , double check that's did receive. if expectation doesn't match, reject input (an http 400 bad request response may in order).

if want limit acceptable set of characters user may input, need checking , rejecting characters independent of encoding. can in javascript @ input time, , need on server again (since browser-side javascript has no influence on can submitted server).


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -