• Resolved Fody

    (@fodisery)


    Is it possible to force advert_phone field to validate and filtered as international format (starts with + sign)

Viewing 1 replies (of 1 total)
  • Plugin Author Greg Winiarski

    (@gwin)

    You can add custom phone number validation by adding the code below in your theme functions.php file

    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";
    }
    }

    In the preg_match() function you just need to update the patter to allow the phones in your desired format.

Viewing 1 replies (of 1 total)

The topic ‘adverts_phone International format’ is closed to new replies.