Skip to content

Instantly share code, notes, and snippets.

@yuriitaran
Last active March 11, 2018 08:37
Show Gist options
  • Save yuriitaran/84c3213579f228e0faaccaa1f48553a0 to your computer and use it in GitHub Desktop.
Save yuriitaran/84c3213579f228e0faaccaa1f48553a0 to your computer and use it in GitHub Desktop.
Reg_exp examples /preg_match / regexp
// clean phone number for link "tel:1234567"
preg_replace("#(?<=\d)[\s-]+(?=\d)#","", $number)
// phone number
preg_match('/^\+[0-9\-\s]*(\([0-9]+\))?[0-9\-\s]*$/', $number)
// email
preg_match("/[0-9a-z]+@[a-z.]/", $email)
// phone number with WP ACF
<?php if (preg_match('/^[0-9\-\s]*(\([0-9]+\))?[0-9\-\s]*$/', $phone)): ?>
<span><a href="tel:<?php echo preg_replace('/\s+/', '', $phone); ?>"><?php echo $phone; ?></a></span>
<?php else: ?>
<span><?php echo $phone; ?></span>
<?php endif ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment