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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21282049/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 00:38:19  来源:igfitidea点击:

HTML5 pattern allow specific special characters

htmlinputspecial-characters

提问by user3117337

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 ??

我怎么能改变可以接受所有字符/特殊字符和其他特殊字符的模式?

回答by Curtis Blackwell

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

回答by user3117337

For Not allowing Specific Symbols (dont allow , or .)

不允许使用特定符号(不允许 , 或 .)

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