Good day! There is such a field

<input type="text" name="fio" id="order_input" pattern="^[A-Za-zА-Яа-яЁё\s]+$" required=""/> 

If it is empty then everything is fine, it gives an error to fill in the field, but if you just drive in a couple of spaces, then validation does not work, although the field is still empty. What to do?

    1 answer 1

    In your version, regexp sets a space as a valid character along with letters, but does not indicate that first the letters and then the space. Therefore, we need a genuine:

     pattern="^[A-Za-zА-Яа-яЁё]+(\s[A-Za-zА-Яа-яЁё]+)*$" 

    That is: first one or more letters, then zero or more groups "one space and followed by one or more letters."