Regular Expressions
Here's an example.
Peruse its source code.
Observe:
- A regular expression tests for digits.
- The pattern match is sought with the test() method.
Lab
Your task:
- Copy the example and edit it as follows.
- Modify the text string pattern match to alert if it
does not contain at least one non-alphabetic character
(a digit or punctuation mark).
Solution
Don't peek unless you're stuck!
Extra for Experts
- Write the regular expression
that validates a Schwab account number.
These are of the form XXXX-XXXX where
X is a digit and the hyphen is optional.
- Write the regular expression
that validates a simplified phone number.
These are of the form (XXX) XXXX-XXXX where
X is a digit, the area code is optional, and
the parentheses, space, and hyphen are optional.