October 2002
Intermediate to advanced
1024 pages
27h 26m
English
You want to classify values into broad categories.
Use a pattern that is similarly broad.
If you need to know only whether values are empty, nonempty, or consist only of certain types of characters, patterns such as the following may suffice:
|
Pattern |
Type of value the pattern matches |
|---|---|
/^$/ |
Empty value |
/./ |
Nonempty value |
/^\s*$/ |
Whitespace, possibly empty |
/^\s+$/ |
Nonempty whitespace |
/\S/ |
Nonempty, and not just whitespace |
/^\d+$/ |
Digits only, nonempty |
/^[a-z]+$/i |
Alphabetic characters only (case insensitive), nonempty |
/^\w+$/ |
Alphanumeric or underscore characters only, nonempty |