Pattern doesn’t allow accented character?

Asked

Viewed 2,063 times

5

I have a form and am validating as follows:

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

But if I type in some accented character (á, à, ã, ç) it does not validate, it has some specific character that allows typing this character type?

  • changes the encooding

1 answer

5


There are two errors and a problem in the Regular Expression attribute Pattern that you defined.

  1. I couldn’t make a letter bar equivalent to the POSIX class [[:alnum:]_] work, so what you have for non-numeric characters today does not consider accents. Enlarge the list solves:

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

    [A-Za-zÀ-ú0-9-]
    
  3. Fixing the first two this becomes optional, but white spaces need not appear more than once:

    [A-Za-zÀ-ú0-9., -]{5,}
    

Example in the Jsbin

  • perfect, thanks!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.