Skip to content

Instantly share code, notes, and snippets.

@nei
Last active November 6, 2019 05:06
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 nei/a7d7b8789bc30b17c4b7d41cd516f87b to your computer and use it in GitHub Desktop.
Save nei/a7d7b8789bc30b17c4b7d41cd516f87b to your computer and use it in GitHub Desktop.
Check if number is a valid UK mobile number.
<?php
/**
* Function to validate if the phone number is Uk Mobile number
* Optinal first part: '+44' or '44', also a
* Optinal second part: '0'
* Mandatory: 7 followed by [1-9] excluding 0,2 followed by 8 digits
* Reference: https://en.wikipedia.org/wiki/Telephone_numbers_in_the_United_Kingdom
*
* @param $number
* @return bool
*/
function isMobileNumber($number)
{
return preg_match('/^(^\+(44)|(44))?(0)?(7[1|3-9][0-9]{8})$/', $number);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment