任何人都可以帮助将这种php regex模式转换为js兼容模式吗?

$delimiter = "-";
$phone = "some number from the client";
var_dump(
    preg_match($phone,"|^([0-9]{1,3}".$delimiter."[0-9]{1,4}".$delimiter."[0-9]{4,12}(#[0-9]{1,4})?)$|")
);


谢谢

最佳答案

var delimiter = "-",
    phone = "8-989-895",
    re = new RegExp("^[0-9]{1,3}"+delimiter+"[0-9]{1,4}"+delimiter+"[0-9]{4,12}(?:[0-9]{1,4})?$");
console.log(re.test(phone));

关于javascript - 将preg_match模式转换为javascript模式,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6175398/

10-11 05:39