Skip to content

Instantly share code, notes, and snippets.

@asllanmaciel
Created July 27, 2023 09:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asllanmaciel/251f08b33f70b0582cb00cf79732121d to your computer and use it in GitHub Desktop.
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
<?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