Why it matters
- A field's
patterndecides what the browser lets people send. When a name field allows Latin letters only, such as[A-Za-z ]+, someone who types their name in Arabic cannot send the form: the browser stops it and asks them to match the requested format, without saying that Arabic is the problem. - Ranges such as
[ا-ي]look like the whole alphabet but leave out the letters that come before ا in Unicode: ء أ إ آ ؤ ئ. «محمد» passes, and «أحمد» and «إياد» do not. - Names are asked for in sign-up, checkout, booking and contact forms; a person who cannot get past the name field cannot finish them.
Example
<label for="name">الاسم الكامل</label> <input id="name" name="full_name" autocomplete="name" pattern="[A-Za-z ]{3,40}" required />
<label for="name">الاسم الكامل</label> <input id="name" name="full_name" autocomplete="name" pattern="[\p{L}\p{M} '\-]{2,60}" />
How to fix
- Allow the letters of every script with Unicode properties, which browsers understand in
pattern:pattern="[\p{L}\p{M} '\-]{2,60}".\p{M}keeps harakat such as the shadda. - Or drop the pattern and limit the length with
minlengthandmaxlength. - If you also need the name in Latin letters, for a passport or a payment card, ask for it in a field of its own that says so.
- Accept the same names on the server.
How we detect
- We find text fields for a person's name:
autocompletename,given-name,additional-name,family-nameornickname, or a name, id, label or placeholder that names a name («الاسم»، «اسم العائلة»، name، first_name…). We leave out user names, company, card and bank names, and fields that ask for the name in English or as in the passport. - We check the field's
patternas browsers do, with thevflag, against Arabic names («محمد العبري»، «عبد الله»، «فاطمة»، «أحمد»، «آمنة»، «يحيى»…) and Latin names of the same length and number of words. - A field fails when it rejects an Arabic name but accepts a name of the same shape, Latin or Arabic. A pattern that rejects every name of a shape, for example one that allows no spaces, is not about Arabic, and does not fail here. Patterns that do not compile are ignored, as browsers ignore them, and so are patterns that take too long to run.
- We check Arabic pages only: those whose
<html lang>is Arabic or whose text is mostly Arabic.