100% Client-Side β’ 0 B Data Leaves Browser
validation
NanoID (21-character) URL-Friendly ID Regex
Validates default 21-character URL-friendly, compact NanoID strings.
Regular Expression Pattern:
/^[A-Za-z0-9_-]{21}$/
Valid Match Example:
V1StGXR8_Z5jdHi6B-myT
Invalid / Non-Match Example:
too_short_id
Regex Syntax Breakdown & Explanation
- β’^[A-Za-z0-9_-]{21}$ : Matches exactly 21 URL-safe characters from the A-Z, a-z, 0-9, _, - alphabet.
Implementation in Popular Languages
JavaScript / TypeScript
const regex = /^[A-Za-z0-9_-]{21}$/;
const isValid = regex.test("V1StGXR8_Z5jdHi6B-myT");
console.log(isValid); // truePython (re)
import re
pattern = r"^[A-Za-z0-9_-]{21}$"
match = re.match(pattern, "V1StGXR8_Z5jdHi6B-myT")
print(bool(match)) # TrueGo (regexp)
package main
import (
"fmt"
"regexp"
)
func main() {
re := regexp.MustCompile(`^[A-Za-z0-9_-]{21}$`)
fmt.Println(re.MatchString("V1StGXR8_Z5jdHi6B-myT"))
}Frequently Asked Questions
Frequently Asked Questions
Everything you need to know regarding specifications, syntax, and security best practices.
The regular expression pattern is /^[A-Za-z0-9_-]{21}$/. Validates default 21-character URL-friendly, compact NanoID strings.