Dev.to WebDev 🛠 Dev 👁 0 📖 2 min read

The Apostrophe and the Hyphen: Two Characters That Break Address Forms

Every address form has two characters that quietly do more damage than the rest: the apostrophe and the hyphen. "O'Connor", "D'Angelo", "Smith-Jones" — ordinary names that break an astonishing number of forms, because so

Every address form has two characters that quietly do more damage than the rest: the apostrophe and the hyphen. "O'Connor", "D'Angelo", "Smith-Jones" — ordinary names that break an astonishing number of forms, because somebody once decided a name should match ^[A-Za-z ]+$.

The regex that rejects real people

Validation like /^[A-Za-z ]+$/ feels reasonable until you meet a customer with an apostrophe, a hyphen, an accent or a name that uses a script outside the Latin alphabet. The form rejects them, and the error message — "Please enter a valid name" — is both wrong and insulting. The name was valid. The validator was not.

The problem compounds downstream. An apostrophe in a name that gets interpolated into a SQL string without escaping produces a syntax error or, worse, an injection vector. A name that exceeds a column's length gets silently truncated. A CSV export that does not quote its fields shifts every column to the right.

Do not over-validate names

The practical rule is to validate names as little as possible. Reject empty strings and obvious junk, impose a generous upper bound for storage, and otherwise accept what the user types. People know their own names far better than your regex does. Let the database use a Unicode-aware text type, escape values properly in queries, and quote fields in exports.

The same restraint applies to street lines. "Apt 4B", "Suite 200" and "#12" are legitimate, as are accented street names and addresses in countries whose format you did not design for. A street field that accepts a broad range of characters and preserves them exactly is more useful than one that enforces a narrow idea of tidiness.

Test with names that break naive validators

None of this shows up if every fixture is "John Doe". Put a set of awkward records into your test suite: a name with an apostrophe, one with a hyphen, one with an accent, a very long surname, a unit designator, and a leading-zero ZIP. Run them through the form, the database, the CSV export and the label generator on every build.

AddressLab is a free, no-sign-up generator for synthetic address records like these. It produces US addresses with names, state, ZIP, phone, email format and a formatted full address field, plus multi-country formats, and exports selected fields as CSV or JSON so you can check a stable set of awkward fixtures into your repo. Generated addresses are for development, testing, education and prototypes — they are not real identities and will not receive mail.

Be generous with what you accept and strict with where you store it. Your customers' names will thank you, and your CSV exports will stop silently corrupting themselves.

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.