Here's a regex pattern you can use to accept only alphabetical characters (both lowercase and uppercase), special characters, and spaces in JavaScript:
index.tsx18 chars2 lines
Breakdown of the pattern:
^
: beginning of the string[a-zA-Z]
: matches any alphabetical character (both lowercase and uppercase)\s
: matches any whitespace character (space, tab, newline)\W
: matches any non-word character (special character)+
: one or more of the above characters$
: end of the stringHere's an example usage in JavaScript:
index.tsx147 chars6 lines
gistlibby LogSnag