true
。用户可以按照他们选择的方式填写表单字段,只要其具有有效美国号码的格式即可。以下是美国数字的有效格式示例(有关其他变体,请参阅下面的测试): 555-555-5555对于此挑战,您将看到一个字符串,如
(555)555-5555
(555)555-5555
555 555 5555
5555555555
1 555 555 5555
800-692-7753
或8oo-six427676;laskdjf
。您的工作是根据上面提供的任何格式组合验证或拒绝美国电话号码。区号是必需的。如果提供了国家/地区代码,则必须确认国家/地区代码为1
。如果字符串是有效的美国电话号码,则返回true
;否则返回false
。如果卡住,请记得使用Read-Search-Ask 。尝试配对程序。编写自己的代码。 telephoneCheck("555-555-5555")
应该返回一个布尔值。
testString: 'assert(typeof telephoneCheck("555-555-5555") === "boolean", "telephoneCheck("555-555-5555")
should return a boolean.");'
- text: telephoneCheck("1 555-555-5555")
应该返回true。
testString: 'assert(telephoneCheck("1 555-555-5555") === true, "telephoneCheck("1 555-555-5555")
should return true.");'
- text: telephoneCheck("1 (555) 555-5555")
应该返回true。
testString: 'assert(telephoneCheck("1 (555) 555-5555") === true, "telephoneCheck("1 (555) 555-5555")
should return true.");'
- text: telephoneCheck("5555555555")
应该返回true。
testString: 'assert(telephoneCheck("5555555555") === true, "telephoneCheck("5555555555")
should return true.");'
- text: telephoneCheck("555-555-5555")
应该返回true。
testString: 'assert(telephoneCheck("555-555-5555") === true, "telephoneCheck("555-555-5555")
should return true.");'
- text: telephoneCheck("(555)555-5555")
应该返回true。
testString: 'assert(telephoneCheck("(555)555-5555") === true, "telephoneCheck("(555)555-5555")
should return true.");'
- text: telephoneCheck("1(555)555-5555")
应该返回true。
testString: 'assert(telephoneCheck("1(555)555-5555") === true, "telephoneCheck("1(555)555-5555")
should return true.");'
- text: telephoneCheck("555-5555")
应该返回false。
testString: 'assert(telephoneCheck("555-5555") === false, "telephoneCheck("555-5555")
should return false.");'
- text: telephoneCheck("5555555")
应该返回false。
testString: 'assert(telephoneCheck("5555555") === false, "telephoneCheck("5555555")
should return false.");'
- text: telephoneCheck("1 555)555-5555")
应该返回false。
testString: 'assert(telephoneCheck("1 555)555-5555") === false, "telephoneCheck("1 555)555-5555")
should return false.");'
- text: telephoneCheck("1 555 555 5555")
应该返回true。
testString: 'assert(telephoneCheck("1 555 555 5555") === true, "telephoneCheck("1 555 555 5555")
should return true.");'
- text: telephoneCheck("1 456 789 4444")
应该返回true。
testString: 'assert(telephoneCheck("1 456 789 4444") === true, "telephoneCheck("1 456 789 4444")
should return true.");'
- text: 'telephoneCheck("123**&!!asdf#")
应该返回false。'
testString: 'assert(telephoneCheck("123**&!!asdf#") === false, "telephoneCheck("123**&!!asdf#")
should return false.");'
- text: telephoneCheck("55555555")
应该返回false。
testString: 'assert(telephoneCheck("55555555") === false, "telephoneCheck("55555555")
should return false.");'
- text: telephoneCheck("(6054756961)")
应该返回false
testString: 'assert(telephoneCheck("(6054756961)") === false, "telephoneCheck("(6054756961)")
should return false");'
- text: telephoneCheck("2 (757) 622-7382")
应该返回false。
testString: 'assert(telephoneCheck("2 (757) 622-7382") === false, "telephoneCheck("2 (757) 622-7382")
should return false.");'
- text: telephoneCheck("0 (757) 622-7382")
应该返回false。
testString: 'assert(telephoneCheck("0 (757) 622-7382") === false, "telephoneCheck("0 (757) 622-7382")
should return false.");'
- text: telephoneCheck("-1 (757) 622-7382")
应该返回false
testString: 'assert(telephoneCheck("-1 (757) 622-7382") === false, "telephoneCheck("-1 (757) 622-7382")
should return false");'
- text: telephoneCheck("2 757 622-7382")
应该返回false。
testString: 'assert(telephoneCheck("2 757 622-7382") === false, "telephoneCheck("2 757 622-7382")
should return false.");'
- text: telephoneCheck("10 (757) 622-7382")
应该返回false。
testString: 'assert(telephoneCheck("10 (757) 622-7382") === false, "telephoneCheck("10 (757) 622-7382")
should return false.");'
- text: telephoneCheck("27576227382")
应该返回false。
testString: 'assert(telephoneCheck("27576227382") === false, "telephoneCheck("27576227382")
should return false.");'
- text: telephoneCheck("(275)76227382")
应该返回false。
testString: 'assert(telephoneCheck("(275)76227382") === false, "telephoneCheck("(275)76227382")
should return false.");'
- text: telephoneCheck("2(757)6227382")
应该返回false。
testString: 'assert(telephoneCheck("2(757)6227382") === false, "telephoneCheck("2(757)6227382")
should return false.");'
- text: telephoneCheck("2(757)622-7382")
应该返回false。
testString: 'assert(telephoneCheck("2(757)622-7382") === false, "telephoneCheck("2(757)622-7382")
should return false.");'
- text: telephoneCheck("555)-555-5555")
应该返回false。
testString: 'assert(telephoneCheck("555)-555-5555") === false, "telephoneCheck("555)-555-5555")
should return false.");'
- text: telephoneCheck("(555-555-5555")
应该返回false。
testString: 'assert(telephoneCheck("(555-555-5555") === false, "telephoneCheck("(555-555-5555")
should return false.");'
- text: telephoneCheck("(555)5(55?)-5555")
应该返回false。
testString: 'assert(telephoneCheck("(555)5(55?)-5555") === false, "telephoneCheck("(555)5(55?)-5555")
should return false.");'
```