单词以最少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 ]+
更多推荐
发布评论