Skip to content

Instantly share code, notes, and snippets.

View shane-reaume's full-sized avatar

Shane Reaume shane-reaume

View GitHub Profile
@shane-reaume
shane-reaume / validation.php
Created November 2, 2012 23:13
Server-side(PHP) validation of phone number that also prevents multiple of same digit, i.e. all 1's
function phonenumber($value)
{
$areacode = '[2-9]{1}\d{1}\d{1}'; // You might want to specify '2\d\d' (200 to 299)
$prefix = '[2-9]{1}\d{1}\d{1}';
$regex = '#^(\('.$areacode.'\)|'.$areacode.')[\s\.-]?'.$prefix.'[\.-]?\d{4}$#';
if (preg_match($regex, $value))
{
// Number now is in a suitable format
// extract digits -- remove this section to not test repeated pattern