Testing Text Field Limits: A Practical Guide to Long and Repeated Strings
A form field says “maximum 255 characters”. The front end agrees. The database agrees. Then a user pastes a product name with two emoji in it, and the save fails with a vague error.
Length limits are one of the most common places for input bugs to hide. They are also easy to test, once you have the right strings ready. This guide covers which strings to build, where to aim them, and a few quick ways to make them without writing a script.
Why length bugs happen
A single text value usually passes through several layers: the HTML input, front-end validation, an API, server-side validation and a database column. Each layer can have its own limit, and each can count characters differently.
When the limits disagree, you get the classic bugs:
- Silent truncation. The database cuts the value and saves only part of it, with no error.
- Rejected saves. The front end allows 255, the API allows 200, and the user sees a generic failure.
- Layout overflow. A long word with no spaces breaks a card, a table or a mobile screen.
- Encoding surprises. Emoji and some scripts take more storage than plain letters.
Boundary value analysis, applied to text
Boundary value analysis says bugs cluster at the edges of a valid range. For a text field with a limit of N characters, test at least these lengths:
| Length | Expected result |
|---|---|
| 0 (empty) | Required field error, or saved as empty |
| 1 | Saved |
| N − 1 | Saved in full |
| N | Saved in full |
| N + 1 | Clear validation error, never silent truncation |
| Far above N (10 × N) | Clear error, no crash or timeout |
Run the same set through the UI and directly against the API. A limit that exists only in the browser is not a limit.
The strings worth having ready
One long run of the letter “a” catches some bugs, but not all. Keep a small set of repeated strings for different jobs:
- Single character, repeated.
aaaa…at exact lengths. The basic boundary test. - Numbered markers. Repeat
1234567890so the position of every character is visible. If a value comes back cut, you can see exactly where it stopped. - Word plus space. Repeat
testto check wrapping, line height and how the field handles trailing spaces. - No spaces at all. One very long unbroken string checks overflow on cards, tables and mobile layouts.
- Line breaks. The same word repeated on separate lines checks textareas, line limits and how new lines are stored.
- Emoji. Repeat a single emoji such as 😀 to test encoding and length counting.
- Combining characters. An “é” built as “e” plus a combining accent looks like one character but is stored as two.
- Right-to-left text. A repeated Arabic or Hebrew word checks text direction and alignment.
The emoji trap: not every layer counts the same way
This is where most length bugs come from. Different layers measure “characters” in different units:
- In JavaScript,
"😀".lengthreturns 2, because strings are counted in UTF-16 code units. - The HTML
maxlengthattribute also counts UTF-16 code units, so one emoji uses two of the allowed characters. - A MySQL
VARCHAR(255)column counts characters, but it needs theutf8mb4character set to store emoji at all. The olderutf8(utf8mb3) set cannot hold them. - Many back-end languages count Unicode code points, so the same emoji counts as 1.
So a 255-character field can accept a value in the browser that the server counts differently, or the reverse. Test your boundary lengths twice: once with plain letters and once with emoji.
Quick ways to generate test strings
You do not need a test framework to build these strings.
- In code: Python’s
"a" * 256or JavaScript’s"a".repeat(256)gives an exact length in one line. - In a spreadsheet:
=REPT("1234567890", 26)in Excel or Google Sheets builds a 260-character marker string you can copy. - In the browser: for quick one-off checks, a free online text repeater repeats any word, emoji or line a set number of times, ready to copy and paste into the form you are testing.
Whatever you use, check the final length with a character counter before you paste. A string that is 254 or 257 characters by accident tests the wrong boundary.
