Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript Regular Expressions in JavaScript Validating a Form Validating a Phone Number

Victor Stanciu
seal-mask
.a{fill-rule:evenodd;}techdegree
Victor Stanciu
Full Stack JavaScript Techdegree Student 11,184 Points

Why did we use "\s" and not just a simple " " (just a space)?

Shouldn't we use just a space " " instead of whitespace? I tried the regex with whitespace on regex101.com and it also matches the telephone number if I press enter instead of space (meaning writing the telephone number on two lines).

I know this case might be basically impossible in a form, but still I think a space is better.

1 Answer

Jason Larson
Jason Larson
7,955 Points

Honestly, I don't think there's a good reason for using the \s in this regex. In fact, the instructor states that he's putting in a space when he puts in the \s, so I agree with you that a simple space is appropriate here.