Hi,
we do not have a phone number validator in the WPAdverts but it should be possible to add it by adding the code below in your theme functions.php file (or even better by creating new blank plugin and pasting it there https://wpadverts.com/blog/how-to-use-code-snippets-in-wordpress/).
add_action( "init", function() {
if( ! defined( "ADVERTS_PATH" ) ) {
return;
}
adverts_form_add_validator("my_is_phone_number", array(
"callback" => "my_is_phone_number",
"label" => "Phone",
"params" => array(),
"default_error" => __( "Provided phone format is invalid", "wpadverts" ),
"validate_empty" => false
));
});
add_filter( "adverts_form_load", function( $form ) {
if( $form["name"] != "advert" ) {
return $form;
}
foreach( $form["field"] as $k => $f ) {
if( $f["name"] == "adverts_phone" ) {
$form["field"][$k]["validator"][] = array( "name" => "my_is_phone_number");
}
}
return $form;
});
function my_is_phone_number( $data ) {
if(preg_match("/^[0-9]{3}-[0-9]{3}-[0-9]{4}$/", $data)) {
return true;
} else {
return "invalid";
}
}