Pattern does not allow accented character?

5

I have a form and I'm validating it as follows:

<input type="text" name="assunto" tabindex="5" pattern="[a-zA-Z0-9. - , ]{5,}" required>

But if you type some accented character (á, à, ã, ç) it does not validate, does it have any specific pattern that allows you to type this type of character?

    
asked by anonymous 14.11.2014 / 16:30

1 answer

4

There are two errors and one problem in the Regular Expression of the pattern attribute that you have defined.

  • I could not make a slash equivalent to the POSIX class [[:alnum:]_] work, so what you have for non-numeric characters today does not consider accents. Expand the list resolves:

    [A-Za-zÀ-ú0-9]
    
  • The hyphen is a special character within a list. Either you escape it or add it to the bottom of the list:

    [A-Za-zÀ-ú0-9-]
    
  • Correcting the first two, this becomes optional, but blanks need not appear more than once:

    [A-Za-zÀ-ú0-9., -]{5,}
    
  • Example in JSBin

        
    14.11.2014 / 16:38