![](/img/trans.png)
[英]javascript regex to allow numbers and special characters but not zeroes only
[英]how to not allow user to give special characters, numbers , spaces only in first place of word in html using regex
如何不允许用户使用正则表达式在 html 中仅在单词的首位给出特殊字符、数字和空格。
<label><span>Current Carrier</span></label>
<input name='Current Carrier' type='text' class='form-control' pattern='[a-zA-Z]+$' for Physical Address'/>
您可以使用
pattern="[A-Za-z].*"
详情:
^(?:[A-Za-z].*)$
正则表达式模式,该模式与字符串开头的 ASCII 字母匹配,然后可以包含除换行符以外的任何零个或多个字符,如尽可能多,直到输入字符串的末尾.*
是必需的,因为pattern
正则表达式必须匹配整个输入请参阅下面的现场演示:
input:valid { color: black; } input:invalid { color: red; }
<form name="form1"> <input pattern="[A-Za-z].*" title="Please enter the data in correct format." /> <input type="Submit" /> </form>
您可以尝试正则表达式中的胡萝卜符号 -> 类似于/^[A-Za-z]/ -> 这将匹配第一个字符并告知它必须是字母,不能是空格、数字或特殊字符特点。
您可以在那之后编写剩余的正则表达式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.