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
Learn two common methods in JavaScript that leverage the power of regular expressions: test() and replace().
Resources
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
Let's look at two JavaScript methods we'll
use to accomplish the behavior you saw
0:00
in the demo.
0:00
First, the test method lets you check to
see if a string matches the pattern you've
0:01
defined in a regular expression.
0:05
To use it,
you create a regular expression.
0:08
Then call the test method while
passing the string you wish to check.
0:11
This is the JavaScript equivalent of
typing a regex into the top window of
0:15
regex pal and
a test string into the lower window.
0:20
This method will return true if the regex
matches the string and false if not.
0:24
To format the telephone number,
we'll us replace().
0:29
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