Created
July 27, 2023 09:48
-
-
Save asllanmaciel/251f08b33f70b0582cb00cf79732121d to your computer and use it in GitHub Desktop.
Para validar um campo usando o padrão 99-99999-9999 no PHP, WordPress e Elementor, você pode usar esse código
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function validatePhoneNumber($phone_number) { | |
// Check if the phone number is empty | |
if (empty($phone_number)) { | |
return false; | |
} | |
// Check if the phone number is 10 digits long | |
if (strlen($phone_number) != 10) { | |
return false; | |
} | |
// Check if the phone number has the correct format | |
if (!preg_match('/^[0-9]{3}-[0-9]{3}-[0-9]{4}$/', $phone_number)) { | |
return false; | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment