.t { margin-bottom: 0.5em; border: 1px solid #ccc; outline: none; } .t:focus { border-color: #abf; } .t:valid { border-color: #9d0; } <input class="t" pattern='^[a-zA-Z]+$' required> .t { margin-bottom: 0.5em; border: 1px solid #ccc; outline: none; } .t:focus { border-color: #abf; } .t:valid { border-color: #9d0; } <input class="t" pattern='^[a-zA-Z]+$' required> The \s pattern finds any whitespace characters, \s+ finds any 1 or more whitespace characters.
You can use pattern="[A-Za-z]+\s+[A-Za-z]+" :
.t { margin-bottom: 0.5em; border: 1px solid #ccc; outline: none; } .t:focus { border-color: #abf; } .t:valid { border-color: #9d0; } <input class="t" pattern="[A-Za-z]+\s+[A-Za-z]+" required> In the pattern attribute, the HTML5 engine wraps the pattern in ^(?: ... )$ and pattern="[A-Za-z]+\s+[A-Za-z]+" will be compiled as new RegExp("^(?:" + шаблон + ")$") . The u flag is added to Chrome and Firefox: new RegExp("^(?:" + шаблон + ")$", "u") - be on the lookout.
Details
^(?: - the beginning of the line and the beginning of the undetectable (non-capturing) submasks[A-Za-z]+ - 1 or more ASCII letters\s+ - 1 or more whitespace characters[A-Za-z]+ - 1 or more ASCII letters)$ - end of trap and end of line. .t { margin-bottom: 0.5em; border: 1px solid #ccc; outline: none; } .t:focus { border-color: #abf; } .t:valid { border-color: #9d0; } <input class="t" pattern='[a-zA-Z]+\s+[a-zA-Z]+$' required> Source: https://ru.stackoverflow.com/questions/846941/
All Articles
pattern="[a-zA-Z]+\s[a-zA-Z]+"?pattern="[a-zA-Z]+(?:\s[a-zA-Z]+)?"? What exactly are the requirements for the pattern? Your expression does not allow spaces at all. Note that^and$not needed here. - Wiktor Stribiżew