你能否帮我转换到PHP regex下面的JavaScript,它正在使用以下过滤器?
function custom_filter_wpcf7_is_tel( $result, $tel ) {
$result = preg_match( '/^((\(?\+45\)?)?)(\s?\d{2}\s?\d{2}\s?\d{2}\s?\d{2})$/', $tel );
return $result;
}
add_filter( 'wpcf7_is_tel', 'custom_filter_wpcf7_is_tel', 10, 2 );
当我把它放到所需的jQuery代码中时:
$.validator.addMethod(
"regex",
function(value, element, regexp) {
var re = new RegExp(regexp);
return this.optional(element) || re.test(value);
},
"Indtast et gyldigt telefonnummer."
);
$( "#lt_phone" ).rules( "add", {
regex: "/^((\(?\+45\)?)?)(\s?\d{2}\s?\d{2}\s?\d{2}\s?\d{2})$/",
});
我有无效的regexp组错误。
我尝试使用regex101.com和一些谷歌搜索以不同的方式编辑我的正则表达式,但没有运气。