Third project for freeCodeCamp's JavaScript Data Structures & Algorithms certification course -- Build a Telephone Number Validator.
In the US, phone numbers can be formatted in many ways. Here are some examples of valid formats for US phone numbers:
1 555-555-5555 1 (555) 555-5555 1(555)555-5555 1 555 555 5555 5555555555 555-555-5555 (555)555-5555
Note that the area code is required. Also, if the country code is provided, you must confirm that the country code is 1.
Objective: Build an app that is functionally similar to https://telephone-number-validator.freecodecamp.rocks
- You should have an
input
element with anid
of"user-input"
√ - You should have a
button
element with anid
of"check-btn"
√ - You should have a
button
element with anid
of"clear-btn"
√ - You should have a
div
,span
orp
element with anid
of"results-div"
√ - When you click on the
#check-btn
element without entering a value into the#user-input
element, an alert should appear with the text"Please provide a phone number"
√ - When you click on the
#clear-btn
element, the content within the#results-div
element should be removed √ - When the
#user-input
element contains1 555-555-5555
and the#check-btn
element is clicked, the#results-div
element should contain the text"Valid US number: 1 555-555-5555"
√ - When the
#user-input
element contains1 (555) 555-5555
and the#check-btn
element is clicked, the#results-div
element should contain the text"Valid US number: 1 (555) 555-5555"
√ - When the
#user-input
element contains5555555555
and the#check-btn
element is clicked, the#results-div
element should contain the text"Valid US number: 5555555555"
√
More user stories...
- When the
#user-input
element contains555-555-5555
and the#check-btn
element is clicked, the#results-div
element should contain the text"Valid US number: 555-555-5555"
√ - When the
#user-input
element contains(555)555-5555
and the#check-btn
element is clicked, the#results-div
element should contain the text"Valid US number: (555)555-5555"
√ - When the
#user-input
element contains1(555)555-5555
and the#check-btn
element is clicked, the#results-div
element should contain the text"Valid US number: 1(555)555-5555"
√ - When the
#user-input
element contains555-5555
and the#check-btn
element is clicked, the#results-div
element should contain the text"Invalid US number: 555-5555"
√ - When the
#user-input
element contains5555555
and the#check-btn
element is clicked, the#results-div
element should contain the text"Invalid US number: 5555555"
√ - When the
#user-input
element contains1 555)555-5555
and the#check-btn
element is clicked, the#results-div
element should contain the text"Invalid US number: 1 555)555-5555"
√ - When the
#user-input
element contains1 555 555 5555
and the#check-btn
element is clicked, the#results-div
element should contain the text"Valid US number: 1 555 555 5555"
√ - When the
#user-input
element contains1 456 789 4444
and the#check-btn
element is clicked, the#results-div
element should contain the text"Valid US number: 1 456 789 4444"
√ - When
#user-input
contains123**&!!asdf#
and#check-btn
is clicked,#results-div
should contain the text"Invalid US number: 123**&!!asdf#"
√ - When the
#user-input
element contains55555555
and the#check-btn
element is clicked, the#results-div
element should contain the text"Invalid US number: 55555555"
√ - When the
#user-input
element contains(6054756961)
and the#check-btn
element is clicked, the#results-div
element should contain the text"Invalid US number: (6054756961)"
√ - When the
#user-input
element contains2 (757) 622-7382
and the#check-btn
element is clicked, the#results-div
element should contain the text"Invalid US number: 2 (757) 622-7382"
√ - When the
#user-input
element contains0 (757) 622-7382
and the#check-btn
element is clicked, the#results-div
element should contain the text"Invalid US number: 0 (757) 622-7382"
√ - When the
#user-input
element contains-1 (757) 622-7382
and the#check-btn
element is clicked, the#results-div
element should contain the text"Invalid US number: -1 (757) 622-7382"
√ - When the
#user-input
element contains2 757 622-7382
and the#check-btn
element is clicked, the#results-div
element should contain the text"Invalid US number: 2 757 622-7382"
√ - When the
#user-input
element contains10 (757) 622-7382
and the#check-btn
element is clicked, the#results-div
element should contain the text"Invalid US number: 10 (757) 622-7382"
√ - When the
#user-input
element contains27576227382
and the#check-btn
element is clicked, the#results-div
element should contain the text"Invalid US number: 27576227382"
√ - When the
#user-input
element contains(275)76227382
and the#check-btn
element is clicked, the#results-div
element should contain the text"Invalid US number: (275)76227382"
√ - When the
#user-input
element contains2(757)6227382
and the#check-btn
element is clicked, the#results-div
element should contain the text"Invalid US number: 2(757)6227382"
√ - When the
#user-input
element contains2(757)622-7382
and the#check-btn
element is clicked, the#results-div
element should contain the text"Invalid US number: 2(757)622-7382"
√ - When the
#user-input
element contains555)-555-5555
and the#check-btn
element is clicked, the#results-div
element should contain the text"Invalid US number: 555)-555-5555"
√ - When the
#user-input
element contains(555-555-5555
and the#check-btn
element is clicked, the#results-div
element should contain the text"Invalid US number: (555-555-5555"
√ - When
#user-input
contains(555)5(55?)-5555
and#check-btn
is clicked,#results-div
should contain the text"Invalid US number: (555)5(55?)-5555"
√ - When the
#user-input
element contains55 55-55-555-5
and the#check-btn
element is clicked, the#results-div
element should contain the text"Invalid US number: 55 55-55-555-5"
√ - When the
#user-input
element contains11 555-555-5555
and the#check-btn
element is clicked, the#results-div
element should contain the text"Invalid US number: 11 555-555-5555"
√