Regex for Minimum Length Validation
Validate minimum string length with this regex. Ensures input has at least 8 characters. Adjustable for any minimum length. Free tool.
Regular Expression
/^.{8,}$/
Token Breakdown
| Token | Description |
|---|---|
| ^ | Anchors at the start of the string (or line in multiline mode) |
| . | Matches any character except newline (unless dotAll flag is set) |
| {8,} | Matches 8 or more times |
| $ | Anchors at the end of the string (or line in multiline mode) |
Detailed Explanation
This regex validates that a string meets a minimum length requirement of 8 characters. Here is the token-by-token breakdown:
^ — Anchors the match at the start of the string. This is essential to ensure we are measuring the length of the entire string, not a substring.
. — The dot metacharacter matches any single character except a newline. In combination with the quantifier, it matches any content.
{8,} — A quantifier specifying that the preceding element (the dot) must occur at least 8 times, with no upper limit. The comma after 8 with no second number means 'eight or more'. If you wanted a maximum length too, you would use {8,20} for 8 to 20 characters.
$ — Anchors the match at the end of the string.
Together, ^.{8,}$ means the string must contain at least 8 characters of any type (except newlines). This is one of the simplest regex patterns but also one of the most commonly used, especially in form validation.
To change the minimum length, simply replace the number 8 with your desired minimum. For example, ^.{6,}$ requires at least 6 characters, and ^.{12,}$ requires at least 12. This pattern is frequently combined with other patterns using lookaheads, as seen in the strong password pattern, where length is checked alongside character type requirements.
Note that this pattern counts all characters equally, including spaces, punctuation, and special characters. If you need to count only specific types of characters toward the minimum, you would replace the dot with a more specific character class.
Example Test Strings
| Input | Expected |
|---|---|
| longpassword | Match |
| 12345678 | Match |
| short | No Match |
| exactly8 | Match |
| 1234567 | No Match |
Try It — Interactive Tester
7 charsFlags: noneMatches: 0Ctrl+Shift+C to copy regex
Related Regex Patterns
Regex for Strong Password Validation
/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[!@#$%^&*()_+\-={}\[\]:;"'<>,.?/~`|\\]).{8,}$/
Regex to Match Alphanumeric Strings
/^[a-zA-Z0-9]+$/
Regex to Match Strings Without Special Characters
/^[a-zA-Z0-9\s]+$/
Regex to Match Programming Variable Names
/^[a-zA-Z_$][a-zA-Z0-9_$]*$/