Why it matters
- A customer who writes the street, the district or the city in Arabic cannot place the order: the browser says the value does not match the format, often in words the customer cannot read, and the sale ends there.
- The pattern comes from a copied template, a validation snippet from an English-language tutorial, or a courier's requirement for Latin addresses that the form enforces on everyone.
- A Gulf address is Arabic by nature: «حي الروضة»، «شارع الملك فهد»، «مبنى 12». The same test the rule about names makes, with addresses.
Example
<label for="city">المدينة</label> <input id="city" name="city" autocomplete="address-level2" pattern="[A-Za-z ]{2,40}" />
<label for="city">المدينة</label> <input id="city" name="city" autocomplete="address-level2" pattern="[\p{L}\p{M} \-]{2,40}" />
How to fix
Let the field take letters of any script, with digits and the punctuation of addresses:
html
<label for="city">المدينة</label>
<input id="city" name="city" autocomplete="address-level2" pattern="[\p{L}\p{M} \-]{2,40}" />\p{L}is any letter (Arabic included),\p{M}the marks that go on them (harakat),\p{N}any digit.- For the street, add digits and the commas:
[\p{L}\p{M}\p{N} ,.،\-]{5,80}. - Better, drop the pattern: let the server validate. Browsers use it to block the order without telling the customer why in a way that fits an Arabic form.
- If the courier needs a Latin address, ask for it in a second field, labelled for it, and leave the Arabic one free.
How we detect
- We find the address fields: text inputs with a
patternwhoseautocompleteis an address token, or whose name, id or label says address, street, city, district, area, governorate («العنوان»، «الشارع»، «المدينة»، «الحي»…). Email, phone, postal code and country fields are left out. - We run the pattern, as a browser does (the whole value, the
vflag), on five Arabic addresses and their Latin equivalents: «الرياض»، «مسقط»، «حي الروضة»، «شارع الملك فهد، حي العليا»، «مبنى 12، الطابق الثالث». - The field fails when it refuses an Arabic one it would take in Latin letters. A pattern that refuses both, such as digits only, is not judged here.
Patterns that take too long to run are skipped, as the rule about names does. We never type in the field and never submit the form.