如何限制 html 中的文本框只接受带有 space 的字母?

How to restrict textbox in html to only accept letters with space?

我想限制文本框只接受带空格的字母。 我已经试过了,但它不接受空格

<input type="text" 
       maxlength = "15"  
       name="txtName" 
       pattern="[A-Za-z \s*]"  
       class="form-control"  
       placeholder="Name" 
       required="required" 
       class="validate">

我也试试这个模式。

pattern="[A-Za-z][" "]" 

我不想在我的代码中为此模式使用任何函数。 我怎样才能用简单的一行代码做到这一点?

您缺少锚点和量词:

pattern="^[A-Za-z \s*]+$"

这是一个有效的 jsfiddle