简体   繁体   English

HTML5 模式允许特定的特殊字符

[英]HTML5 pattern allow specific special characters

I have an input text field in my form but i don't know how to filter the input that can all letters and special characters but will not accept numbers.我的表单中有一个输入文本字段,但我不知道如何过滤可以包含所有字母和特殊字符但不接受数字的输入。

   <input  pattern="[A-Za-z]{1,25}" maxlength="25" type="text" required="required" style="height:20px"  value="">

It doesn't accept when i enter my middle name "pacaña"当我输入我的中间名“pacaña”时它不接受

how could i alter the pattern that can accept all characters/special-characters and other special characters like ñ?我怎样才能改变可以接受所有字符/特殊字符和其他特殊字符(如ñ)的模式?

pattern="[^0-9]*"
  • […] matches a single character […]匹配单个字符
  • ^ anything except the following (when within [] ) ^除以下内容外的任何内容(在[]
  • 0-9 digits zero through nine 0-9位零到九
  • * between zero and unlimited times *零次和无限次之间

For Not allowing Specific Symbols (dont allow , or .)不允许使用特定符号(不允许 , 或 .)

<form>
<input type="text" pattern="[^-,]+" title="'-' is not allowed">
<input type="submit">
</form>

Allow any special symbols : [A-Za-z\\W+]允许任何特殊符号:[A-Za-z\\W+]

 <form action="/action_page.php"> <label for="country_code">Special Symbols Not Allowed:</label> <input type="text" pattern="[A-Za-z]{1,25}" title="Special characters are not allowed!"><br><br> <input type="submit"> </form> <br><br> <form action="/action_page.php"> <label for="country_code">Special Symbols Allowed:</label> <input type="text" pattern="[A-Za-z\\W+]{1,25}" title="Special characters are not allowed!"><br><br> <input type="submit"> </form>

我遇到了同样的问题,想要让法语口音进入文本字段......经过一些反复试验,结果你可以使用pattern="^[\\p{L}]${1,25}来允许 ASCII 字母和 Unicode 变体、重音字母和特殊字符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM