HTML5中的字母正则表达式(Alphabetic Regex in HTML5)
我是regex的新手,但我需要找到一种方法来为HTML5表单添加一个过滤器:
例如,任何人都可以帮我设置模式属性中的内容
公认:
John
Frank
不接受:
Ke$ha
B0B
(只接受字母字符。)
I'm really new to regex but I need to find a way to add a filter to a HTML5 form:
Could anyone help me with what to put in the pattern attribute, for example
Accepted:
John
Frank
Not accepted:
Ke$ha
B0B
(Only alphabetic characters are accepted.)
原文:https://stackoverflow.com/questions/10458189
更新时间:2019-11-02 12:22
最满意答案
在你的情况下我会使用:
[a-zA-Z]+
In your case I would use:
[a-zA-Z]+
相关问答
为此,您可以使用否定前瞻(?!) 。 匹配整个对的示例正则表达式字符串: ]*>.*(?:)? 较短的正则表达式,仅与第一个标签匹配 ]*> 如果存在具有EXCEPT strong或em的HTML标记,则此匹配将通过。 因此,如果match = $ true,您可以拒绝输入并向用户发出警告。 Regex101演示 You can use a Negative Lookahead (?!) for
...
一些很好的例子: http : //html5pattern.com/ 在你的情况下我会使用: [a-zA-Z]+
Some nice examples: http://html5pattern.com/ In your case I would use: [a-zA-Z]+
经过多次头部/桌面敲击后,我想出了解决方案。 它造成的所有麻烦令人烦躁: ^[^\./]+$ 主要有: 如果网址不包含“/”或“。”,请替换。 在它的任何地方。 对于任何使用IIS和Backbone以及HTML5推送状态的人来说,这应该是一个解决方案。 只需在应用程序根目录中的web.config中弹出它,然后将重写操作更改为“。”,它应该可以正常工作。 After much head/desk banging, I've come up with the solution. It's irrit
...
您的模式允许空格( * )或空字符串。 使模式至少匹配: 性别 : pattern="[MmFf]" 等级 : pattern="0?[0-9]|1[0-2]|[A-Za-z]{1,2}" 请注意,HTML5模式不需要显式的^和$ anchors(除非一些不寻常的框架覆盖HTML5 pattern行为)。 因此,第一个模式将被转换为^(?:[MmFf])$ pattern,并且只匹配等于M , m , F或f的字符串。 第二个将被翻译成^(?:0?[0-9]|1[0-2]|[A-Za-z]{1,2
...
你可能正在寻找这个: ^[^.-].{1,23}[^.-]$
^表示从字符串的开头开始,除了在[]里面,这意味着not . 表示除换行符之外的任何字符,但[]表示句点 -通常用作[] ( Az )内的范围,除非它被放置在它只是意味着减号的末尾。 可能是一个更好的解释者: https://regex101.com/r/OYRnMO/1 You're probably looking for this: ^[^.-].{1,23}[^.-]$
^ means starting at the beg
...
pattern="(?=.*\d)(?=.*[a-z])(?=.*[()\[\]{}?!$%&/=*+~,.;:<>_-])(?=.*[A-Z]).{9,}"
有几个错误: ^(?=.*\d)(?=.*[a-z])(?=.*[()[]{}?!$%&/=*+~,.;:<>-_])(?=.*[A-Z]).{9,}?$
# ] needs to be escaped ----^^ ^ ^
# otherwise it will cl
...
例如,您可以使用十六进制值: \x26 见这里: http : //regex101.com/r/bF4bZ3 换句话说, [....$%&'*....]将成为[....$%\x26'*....] 。 其余的都做同样的事情。 You can, for example, use the hex value: \x26 See here: http://regex101.com/r/bF4bZ3 In other words, [....$%&'*....] would become [....$%\
...
pattern属性必须匹配整个字符串。 断言检查匹配,但不计入总匹配长度。 将第二个断言更改为\w+将使模式与整个字符串匹配。 您也可以跳过隐含的^ ,只留下:
The pattern attribute has to match the entire string. Assertions check for a match, but do not count towards the total match leng
...
以下正则表达式将满足您的所有条件。 您不需要在模式中添加空间, ^(?=.{5,254}$)[a-zA-Z0-9+-.]{1,}@[a-zA-Z0-9+-.]{1,}[.]{1}[a-zA-Z0-9+-.]{1,}
在演示输入中添加单个字符,您可以看到差异。 DEMO The below regex would satisfy all your conditions. You don't need to add space within the pattern, ^(?=.{5,254}$)[a
...