quantifiers include: * = 0 or more + = 1 or more ? = 0 or 1 (optional) {N} = exactly N {N,M} = from N to M characters this pattern validates usernames which are alpha numeric and 6 to 8 characters in length | ||
Pattern --> | /^\w{6,8}$/ | |
---|---|---|
username | MATCH | |
a1 | DOES NOT MATCH | |
db2248 | MATCH | |
thisnameisway2long | DOES NOT MATCH |
US postal codes are in this form: nnnnn or nnnnn-nnnn the last "-nnnn" is optional | ||
Pattern --> | /^\d{5}(-\d{4})?$/ | |
---|---|---|
M5K 1A1 | DOES NOT MATCH | |
AB11 6EW | DOES NOT MATCH | |
14609-1234 | MATCH | |
H2Y 1Z7 | DOES NOT MATCH | |
10001 | MATCH |