I need help creating the regex for a password.
The password can contain letters, numbers, underscores ( _ ), dollar signs ( $ ) and hyphens ( - ), must be at least 3 characters long and at most 30 characters long.
I need help creating the regex for a password.
The password can contain letters, numbers, underscores ( _ ), dollar signs ( $ ) and hyphens ( - ), must be at least 3 characters long and at most 30 characters long.
Letters, numbers, underscores, dollar signs and hyphens are covered by this:
[a-zA-Z0-9_$-]
Limiting it to 3 to 30 is covered by this:
{3,30}
In the end, we can reduce it a bit by adding the case-insensitive modifier:
/^[a-z0-9_$-]{3,30}$/i
Adding the ^ and $ force it to match from start to finish, meaning we won't be matching a subset of the tested string. Either the entire submitted string passes, or fails.
You can try it out against a few password by visiting http://regexr.com?30ru6