Skip to content

Instantly share code, notes, and snippets.

@Anyoks
Last active December 31, 2018 10:41
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 Anyoks/5a358993479b5d4932bbba2bac348fe8 to your computer and use it in GitHub Desktop.
Save Anyoks/5a358993479b5d4932bbba2bac348fe8 to your computer and use it in GitHub Desktop.
Matching Kenyan Phone Numbers with a reular expression.txt
To match 07xx xxx xxx number
/^0(7(?:(?:[129][0-9])|(?:0[0-8])|(4[0-1]))[0-9]{6})$/
To match +254 7xx xxx xxx
/^(?:+254)?(7(?:(?:[129][0-9])|(?:0[0-8])|(4[0-1]))[0-9]{6})$/
To match 254 7xx xxx xxx
/^(?:254)?(7(?:(?:[129][0-9])|(?:0[0-8])|(4[0-1]))[0-9]{6})$/
To match all the different number formats
/^(?:254|\+254|0)?(7(?:(?:[129][0-9])|(?:0[0-8])|(4[0-1]))[0-9]{6})$/
https://rubular.com/ to test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment