Re: [PHP] Re: Regex for telephone numbers

Re: [PHP] Re: Regex for telephone numbers

am 31.12.2010 17:10:26 von Ashley Sheridan

------=_Part_2_1293811826631
Content-Type: text/plain;
charset=utf-8
Content-Transfer-Encoding: base64
Content-Disposition: inline

RXJtLCB5b3Ugc2F5IHJlZ2V4IGlzIG92ZXJraWxsLCB0aGVuIHVzZSBvbmUg aW4geW91ciBleGFt
cGxlIQoKVGhhbmtzLApBc2gKaHR0cDovL3d3dy5hc2hsZXlzaGVyaWRhbi5j by51awoKLS0tLS0g
UmVwbHkgbWVzc2FnZSAtLS0tLQpGcm9tOiAiQWwiIDxuZXdzQHJpZGVyc2l0 ZS5vcmc+CkRhdGU6
IEZyaSwgRGVjIDMxLCAyMDEwIDE1OjUzClN1YmplY3Q6IFtQSFBdIFJlOiBS ZWdleCBmb3IgdGVs
ZXBob25lIG51bWJlcnMKVG86IDxwaHAtZGJAbGlzdHMucGhwLm5ldD4sIDxw aHAtZ2VuZXJhbEBs
aXN0cy5waHAubmV0PgoKCgpPbiAxMi8yOS8yMDEwIDc6MTIgUE0sIEV0aGFu IFJvc2VuYmVyZyB3
cm90ZToKPiBEZWFyIExpc3QgLQo+Cj4gVGhhbmsgeW91IGZvciBhbGwgeW91 ciBoZWxwIGluIHRo
ZSBwYXN0Lgo+Cj4gSGVyZSBpcyBhbm90aGVyIG9uZS4uLi4KPgo+IEkgd291 bGQgbGlrZSB0byBo
YXZlIGEgcmVnZXggd2hpY2ggd291bGQgdmFsaWRhdGUgdGhhdCBhIHRlbGVw aG9uZSBudW1iZXIg
aXMKPiBpbiB0aGUgZm9ybWF0IHh4eC14eHgteHh4eC4KPgo+IFRoYW5rcy4K Pgo+IEV0aGFuCj4K
PiBNeVNRTCA1LjEgUEhQIDUgTGludXggW0RlYmlhbiAoc2lkKV0KPgoKUmVn ZXggaXMgb3Zlci1r
aWxsLgoKJHBob25lTnVtID0gcHJlZ19yZXBsYWNlKCIlXEQlIiwgJycsICRw aG9uZU51bSk7Ly9S
ZW1vdmUgZXZlcnl0aGluZyBleGNlcHQgZGlnaXRzCgokcGhvbmVOdW0gPSBs dHJpbSgkcGhvbmVO
dW0sJzEnKTsvL1JlbW92ZSBsZWFkaW5nIDFzCgppZihzdHJsZW4oJHBob25l VmFsdWUpICE9IDEw
KQogICAgIHsKdGhyb3cgbmV3IEV4Y2VwdGlvbigiUGhvbmUgbnVtYmVyIG11 c3QgYmUgMTAgZGln
aXRzLCB3aXRob3V0IGxlYWRpbmcgYSAxLiBDaGVjayAKeW91ciBlbnRyeSBj YXJlZnVsbCIpOwog
ICAgIH0KCi0tIApQSFAgR2VuZXJhbCBNYWlsaW5nIExpc3QgKGh0dHA6Ly93 d3cucGhwLm5ldC8p
ClRvIHVuc3Vic2NyaWJlLCB2aXNpdDogaHR0cDovL3d3dy5waHAubmV0L3Vu c3ViLnBocAoK


------=_Part_2_1293811826631--

Re: Re: Regex for telephone numbers

am 31.12.2010 17:15:53 von Al

On 12/31/2010 11:10 AM, ash@ashleysheridan.co.uk wrote:
> Erm, you say regex is overkill, then use one in your example!
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
> ----- Reply message -----
> From: "Al"
> Date: Fri, Dec 31, 2010 15:53
> Subject: [PHP] Re: Regex for telephone numbers
> To:,
>
>
>
> On 12/29/2010 7:12 PM, Ethan Rosenberg wrote:
>> Dear List -
>>
>> Thank you for all your help in the past.
>>
>> Here is another one....
>>
>> I would like to have a regex which would validate that a telephone number is
>> in the format xxx-xxx-xxxx.
>>
>> Thanks.
>>
>> Ethan
>>
>> MySQL 5.1 PHP 5 Linux [Debian (sid)]
>>
>
> Regex is over-kill.
>
> $phoneNum = preg_replace("%\D%", '', $phoneNum);//Remove everything except digits
>
> $phoneNum = ltrim($phoneNum,'1');//Remove leading 1s
>
> if(strlen($phoneValue) != 10)
> {
> throw new Exception("Phone number must be 10 digits, without leading a 1. Check
> your entry carefull");
> }
>

Save and use the resultant $phoneNum; It is all that needs to be saved and used.
Dashes, spaces and () are superfluous. Only the 10 digits are required for his
application.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php