Html HTML5 输入验证字母和数字
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20287650/
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-28 22:17:06 来源:igfitidea点击:
HTML5 input validate letters and numbers
提问by Jens T?rnell
I need a pattern for a HTML5 form.
我需要一个 HTML5 表单的模式。
- Lowercase letters accepted
- Uppercase letters accepted
- Numbers accepted
- Minus character accepted
- 接受小写字母
- 接受大写字母
- 接受的数字
- 接受减号
HTML so far
到目前为止的 HTML
<input type="text" pattern="[a-zA-Z0-9-]" required>
The code above does not work. I guess I'm close?
上面的代码不起作用。我想我很接近?
回答by Ibrahim Najjar
You are pretty close actually:
你实际上非常接近:
[a-zA-Z0-9-]+
^
You just needed this +
plus quantifier, which tells the input field to accept one or more the characters you have listed in the character class []
.
您只需要这个+
加号量词,它告诉输入字段接受您在字符类中列出的一个或多个字符[]
。