Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed Regular Expressions in JavaScript!
You have completed Regular Expressions in JavaScript!
Preview
Make the telephone validator we wrote earlier more flexible, allowing users to format their input any way they choose.
Resources
The following regex expression can match phone numbers while not allowing for non-digit (a-z) characters:
1?[\s-]?\(?(\d{3})\)?[\s-]?\d{3}[\s-]?\d{4}
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
parentheses [SOUND], a space,
[SOUND] and a hyphen.
0:00
This doesn't provide a very good
experience since our users have
0:03
no flexibility in how they
type in their phone number.
0:06
Some users might feel more comfortable
formatting the number complete with
0:10
parentheses and hyphens [SOUND].
0:14
But a lot of other people would
probably rather just enter the numbers.
0:16
Let's create a regular expression
that can recognize a telephone number
0:20
whether users format it or not.
0:25
I'm in app.js, and here's the telephone
validator we wrote earlier.
0:27
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up