且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

不允许使用空格作为第一个字符,并且只允许使用jquery的字母

更新时间:2023-02-21 12:21:39

可以使用HTML5属性pattern吗?请参见 MDN文章有关更多信息.

Can you use the HTML5 attribute pattern? See the MDN article on it for more information.

使用^[a-zA-Z][\sa-zA-Z]*的正则表达式似乎可以满足您的要求.

Using a regex of ^[a-zA-Z][\sa-zA-Z]* seems to cover your requirements.

所以像这样:

<div>Username:</div>
<input type="text" pattern="^[a-zA-Z][\sa-zA-Z]*" title="Can use upper and lower letters, and spaces but must not start with a space" />