问题
Hi I am using the following regular expression.It works fine in jsfiddle here.
var string="zñáéíóúü1111";
if(/^[0-9a-zñáéíóúü]+$/i.test(string))
{
$("#result").text("oK WITH THE INPUT");
}
else
{
$("#result").text("error");
}
But when I put the code in browser the spanish characters not coming proprely(Some strange characters) (view source code in browser). and the above regular expression not working properly.
But I have the
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
in the browser.
I am not sure about the reason why its not working on my page , when I am getting the input from the user.But I put alert and checked the characters in this string .Both are same.
回答1:
I guess your HTML or JS file or both of them are not saved as UTF-8. You should adjust your editor's charset settings. Depending on the editor you might find them in the save dialog or the files' properties.
回答2:
Follow the below link http://character-code.com/spanish-html-codes.php
for n = ń for i = í
来源:https://stackoverflow.com/questions/17246076/spanish-characters-not-coming-properly-in-javascript