【JS】查验电话号码(fCC)
?.
function telephoneCheck(str) { //排除str中的空格 const strNS = str.match(/\S/ig).join(''); //str中的数字 const allNum = str.match(/\d/ig).join(''); //排除str中的空格和() const strNSB = strNS.match(/-*\d-*/g).join(''); const strB = strNS.match(/[()]/g)?.join(''); console.log(strB); console.log(strB === null ); console.log(strNSB.match(/^1[1-9]{3}-*\d{3}-*\d{4}/g)) if (strB ==='()'){ if (allNum.length === 10) { return strNSB.match(/^[1-9]{3}-*\d{3}-*\d{4}/g) !== null; } else if (allNum.length === 11) { return strNSB.match(/^1[1-9]{3}-*\d{3}-*\d{4}/g) !== null; }else { return false;} } else if (strB === undefined) { if (allNum.length === 10) { return strNSB.match(/^[1-9]{3}-*\d{3}-*\d{4}/g) !== null; } else if (allNum.length === 11) { return strNSB.match(/^1[1-9]{3}-*\d{3}-*\d{4}/g) !== null; }else { return false;} } else { return false; } } console.log(telephoneCheck("-1 (757) 622-7382"));



浙公网安备 33010602011771号