输入字段的模式属性的值,如单词“Kim”,“Kim Sun”,“Kim 2”等(Value for Pattern Attribute for Input Field like words “Kim”

编程入门 行业动态 更新时间:2024-10-28 14:30:44
输入字段的模式属性的值,如单词“Kim”,“Kim Sun”,“Kim 2”等(Value for Pattern Attribute for Input Field like words “Kim”, “Kim Sun”, “Kim 2” etc)

单词以最少3个字母开头,然后可以是空格和数字,例如“Kim”,“Kim Sun”,“Kim 2”等。在这种情况下,html输入字段的pattern属性应该是什么值?

我有一个工作正则表达式的php用于相同的目的"/^[a-zA-Z]{3,}[a-zA-Z0-9 ]+$/i" 。 我试着这样做:

<input class="form-control" type="text" name="name" id="name" value="<?php echo $name;?>" title="Must type a name starting with letters, but then numbers and white space allowed" required="required" aria-required="true" pattern="[a-zA-Z]{3,}[a-zA-Z0-9 ]" spellcheck="false" size="15">

但是pattern属性不起作用。

Words start with minimum 3 letters and then may be a white space and numbers, say "Kim", "Kim Sun", "Kim 2" etc. In this case, what should be the value for pattern attribute for html input field?

I have a working regex for php for the same purpose "/^[a-zA-Z]{3,}[a-zA-Z0-9 ]+$/i". I tried from this as :

<input class="form-control" type="text" name="name" id="name" value="<?php echo $name;?>" title="Must type a name starting with letters, but then numbers and white space allowed" required="required" aria-required="true" pattern="[a-zA-Z]{3,}[a-zA-Z0-9 ]" spellcheck="false" size="15">

But the pattern attribute is not working.

最满意答案

我怀疑问题是你忘了最后的+ 。

尝试: [a-zA-Z]{3,}[a-zA-Z0-9 ]+

I suspect the problem is you forgot the + at the end.

Try: [a-zA-Z]{3,}[a-zA-Z0-9 ]+

更多推荐

本文发布于:2023-07-19 17:12:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1183862.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字段   单词   属性   模式   Kim

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!