Sprinkle in some positive lookahead to test for the total length of the string by adding
(?=.{3,16}$)
at the start of the regex. The final regex is then:
/^(?=.{3,16}$)[a-z][a-z0-9]*(?:_[a-z0-9]+)*$/
More Related Contents:
- RegEx for Multi-Words Without Numbers and Any Special Characters
- What is this pattern “\\s*\\^++\\s*” used for? [duplicate]
- Regular expression to match balanced parentheses
- How do I deal with special characters like \^$.?*|+()[{ in my regex?
- Regular expression that matches valid IPv6 addresses
- How to capture multiple repeated groups?
- Regular expression to enforce complex passwords, matching 3 out of 4 rules
- Regular expression to allow spaces between words
- Regular expression for a string that does not start with a sequence
- Regex: Specify “space or start of string” and “space or end of string”
- Regex – Does not contain certain Characters
- Regex to match all permutations of {1,2,3,4} without repetition
- Is the regular expression [a-Z] valid and if yes then is it the same as [a-zA-Z]?
- Notepad++ Find/Replace number with Increment Value
- Mongodb match accented characters as underlying character
- Have HTML5’s a inputs pattern attribute ignore case
- JSLint reports “Insecure ^” for my regex — what does that mean?
- Match Question Mark in mod_rewrite rule regex
- HTML5 input pattern search for quote
- When should I not use regular expressions?
- regex to remove ordinals
- Replace a word with multiple lines using sed?
- Regular Expression Vs. String Parsing
- .htaccess RewriteRule to path without changing URL
- Can extended regex implementations parse HTML?
- How to get Vim to highlight non-ascii characters?
- Regexp for subdomain
- Regular Expression usage with ls
- Difference between regex quantifiers plus and star
- Finding and removing Non-ASCII characters from an Oracle Varchar2