问题
i'm trying to validate input form html5, it works in my local web server, but when upload to hosting doesnt work in this characters: accented characters (vocals) like áéíóú.
so i have tried changing the encoding, is this the best practice?
<META HTTP-EQUIV="Content-Type" CONTENT="text/html;" charset="ISO-8859-1">
<html>
<head></head>
<body>
<form>
Input:<input type="text" pattern="[a-zA-Z0-9ñÑáéíóúü\-_çÇ& ]+" required />
<input type="submit" />
</form>
</body>
</html>
回答1:
The charset described by the meta tag is not the page's encoding, it's just your claim of what the encoding is.
The actual encoding of the page is whatever encoding you used in your text editor to save the file. It is also possible that the hosting changes the encoding of the file but probably unlikely.
You probably want your tag just to be:
<meta charset="UTF-8">
Remember to ensure that you save the file in UTF-8 encoding. (Usually "Encoding" in Save As-dialog)
It is also possible that the hosting is sending an actual HTTP header with charset - this will override any meta tag you have. You can see if this is the case by using Google Chrome Developer Tools Network tab for example.
来源:https://stackoverflow.com/questions/15791521/html5-form-pattern-latin-characters-vocals-%c3%a1%c3%a9%c3%ad%c3%b3%c3%ba-%c3%87%c3%a7-%c3%bc