【发布时间】:2015-06-19 06:59:01
【问题描述】:
var tel = "123457890";
if (tel.length != 10) {
console.log("Sorry, incorrect format.");
} else {
var areaCode = tel.substring(0,3);
var prefix = tel.substring(3,6);
var suffix = tel.substring(6,10);
console.log("(" + areaCode + ") " + prefix + "-" + suffix);
}
这一切都对我有用,除了我不能让它只检查数字。当我通过建议对其进行故障排除并通过http://repl.it/languages/JavaScript 运行它时,我遇到了错误消息。
即当我输入一个带有 10 个数字的字符串的“w”时,我希望它返回“对不起,格式不正确”,就好像我输入了错误数量的数字等一样。
【问题讨论】:
-
你不能是认真的,哈哈
标签: javascript