2

Basically I'm trying to read raw field values, but cannot in some cases as shown below.

Consider a simple email form field:

<input type="email" name="username" id="username" />

When I input regular email, Javascript can read the value as expected. When I input all Chinese character, Javascript also can read the value as expected. However when I mix latin and Chinese characters, Javascript seems to convert to some sort of code character set.

Test examples:

test@test.com //returns test@test.com 暮捕徹@暮捕徹.暮捕徹 //returns 暮捕徹@暮捕徹.暮捕徹 test@暮捕徹.com //returns test@xn--r5t43fptd.com test@test.暮捕徹 //returns test@test.xn--r5t43fptd

Test code:

function login(){
 var username=document.querySelector('#username').value;
  var resultDiv=document.createElement('DIV');
  resultDiv.innerText = username;
 document.querySelector('body').appendChild(resultDiv);
  return false;
}
<form onsubmit="javascript: return false;">
  <label for="username">Username</label>
  <input type="email" name="username" id="username" />
  <button onclick="login();">
    Login
  </button>
</form>

Things I've Tried:

  • I have set in <head>: <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  • I had set utf-8 in form field: <input type="email" name="username" id="username" accept-charset="utf-8" />
EdC
  • 1,145
  • 10
  • 8
  • Based on Gibolt's answer, I ended up including punycode as part of the input data requirements, and doing my data handling based on this converted string. – EdC Oct 30 '17 at 04:00

1 Answers1

1

This is called Punycode. It converts unicode to latin characters so any device can enter them. You can check out this page to get a more extensive description.

For a solution, please checkout this page and see if it suits your needs. Good luck!

Community
  • 1
  • 1
Gibolt
  • 42,564
  • 15
  • 187
  • 127