[英]Allow special characters in ng-pattern
I am trying to allow some special characters in a field, these characters are the accented vowels (áéíóúÁEÍÍÓÚ), ÑñÇç to allow french and spanish names (ie Nuño, José, François). 我正在尝试在字段中允许一些特殊字符,这些字符是重音元音(áéíóúÁEÍÍÓÚÚ)和ÑñÇç,以允许使用法文和西班牙文名称(例如Nuño,José,François)。 My code goes like this:
我的代码是这样的:
ng-pattern="/^[a-zA-Z\_\-\&\`\#\. ]*$'áéíóúÁEÍÍÓÚÑñÇç"
And I have tried this too 我也尝试过
ng-pattern="/^[a-zA-Z\_\-\&\`\´\#\. ]*$'\á\é\í\ó\ú\Á\É\Í\Ó\Ú\Ñ\ñ\Ç\ç]/"
but when I deploy it in the server, and inspect the field, it changes those characters into unknown characters, like shown below: 但是,当我将其部署到服务器中并检查字段时,它将这些字符更改为未知字符,如下所示:
<input type="text" name="firstName" class="form-control ng-pristine ng-invalid ng-not-empty ng-valid-required ng-invalid-pattern ng-touched" ng-required="!userDetails.user.firstname" ng-pattern="/^[a-zA-Z\_\-\&\`\�'\#\. ]*$'\�\�\�\�\�\�\�\�\�\�\�\�\�\�/" ng-model="userDetails.user.firstname" aria-invalid="true">
How can I make the compiler to recognize the characters i need? 如何使编译器识别我需要的字符?
Thanks 谢谢
/^[a-zA-Z_\\-&`´#\\. / ^ [a-zA-Z _ \\-&`´#\\。 áéíóúÁÉÍÓÚÑñÇç]*$/ should work in you case - you don't need to place an escape literal (\\) in front of a character doesn't need to escape.
* $ /应该适合您的情况-不需要在字符前面放置转义文字(\\),不需要转义。
正如@sln所评论的,它需要unicode字符,它可以与
^[-a-zA-Z_&`´#. \u0027\u00C1\u00C7\u00C9\u00CD\u00D1\u00D3\u00DA\u00E1\u00E7\u00E9\u00ED\u00F1\u00F3\u00FA]*$
如果将html的字符集/编码(可以在浏览器或Web服务器中设置)设置为UTF8,则不需要上述unicode转换。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.