[PHP-DB] Re: [PHP] Regex for telephone numbers

2010-12-31 Thread Daniel P. Brown
On Fri, Dec 31, 2010 at 19:09, Jim Lucas  wrote:
>
> Actually...
>
> Specified here [1] it says that the {1,} is the same as '+'.  I think you 
> should
> drop the comma.  If you don't this would be valid 844-2345-123456
>
> ^[2-9]{1,}[0-9]{2,}\-[2-9]{1,}[0-9]{2,}\-[0-9]{4,}$
>
> should be
>
> ^[2-9]{1}[0-9]{2}\-[2-9]{1}[0-9]{2}\-[0-9]{4}$

Bah, you're absolutely correct.  Force of habit with the commas.
I didn't even notice the sample test cases I put into that test array
didn't check for more than the number of digits per field, either.
Good catch, Jim, and Happy New Year.

-- 

Dedicated Servers, Cloud and Cloud Hybrid Solutions, VPS, Hosting
(866-) 725-4321
http://www.parasane.net/

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



[PHP-DB] Re: [PHP] Regex for telephone numbers

2010-12-31 Thread Jim Lucas
On 12/29/2010 4:35 PM, Daniel P. Brown wrote:
> On Wed, Dec 29, 2010 at 19:12, 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-.
> 
> Congrats.  People in Hell would like ice water.  Now we all know
> that everyone wants something.  ;-P
> 
> Really, this isn't a PHP question, but rather one of regular
> expressions.  That said, something like this (untested) should work:
> 
>  
> $numbers = array(
> '123-456-7890',
> '2-654-06547',
> 'sf34-asdf-',
> 'abc-def-ghij',
> '555_555_',
> '000-000-',
> '8007396325',
> '241-555-2091',
> '800-555-0129',
> '900-976-739',
> '5352-342=452',
> '200-200-2000',
> );
> 
> foreach ($numbers as $n) {
> echo $n.(validate_phone($n) ? ' is ' : ' is not ').'a valid
> US/Canadian telephone number.'.PHP_EOL;
> }
> 
> 
> function validate_phone($number) {
> 
> if 
> (preg_match('/^[2-9]{1,}[0-9]{2,}\-[2-9]{1,}[0-9]{2,}\-[0-9]{4,}$/',trim($number)))
> {
> return true;
> }
> 
> return false;
> }
> ?>
> 
> 

Actually...

Specified here [1] it says that the {1,} is the same as '+'.  I think you should
drop the comma.  If you don't this would be valid 844-2345-123456

^[2-9]{1,}[0-9]{2,}\-[2-9]{1,}[0-9]{2,}\-[0-9]{4,}$

should be

^[2-9]{1}[0-9]{2}\-[2-9]{1}[0-9]{2}\-[0-9]{4}$


1  http://us.php.net/manual/en/regexp.reference.repetition.php

Jim Lucas

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



[PHP-DB] Re: [PHP] Regex for telephone numbers

2010-12-31 Thread Daniel Brown
On Fri, Dec 31, 2010 at 12:05, Dmitriy Ugnichenko
 wrote:
> I guess, this will work fine
>
> ereg('[0-9]{3}-[0-9]{3}-[0-9]{4}',  $phone_number);

Not quite.  Plus, all ereg* functions have been deprecated for
some time now.

-- 

Network Infrastructure Manager
Documentation, Webmaster Teams
http://www.php.net/

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



[PHP-DB] Re: [PHP] Regex for telephone numbers

2010-12-31 Thread Dmitriy Ugnichenko
I guess, this will work fine

ereg('[0-9]{3}-[0-9]{3}-[0-9]{4}',  $phone_number);

On Thu, Dec 30, 2010 at 2:12 AM, 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-.
>
> Thanks.
>
> Ethan
>
> MySQL 5.1  PHP 5  Linux [Debian (sid)]
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
with best regards,
Dmitriy.


Re: [PHP-DB] Re: [PHP] Regex for telephone numbers

2010-12-30 Thread Daniel Brown
On Thu, Dec 30, 2010 at 14:07, Ethan Rosenberg  wrote:
>
> Josh -
>
> I used use \d{3}-\d{3}-\d{4}.
>
> It works beautifully!!

Just keep in mind that invalid numbers will also pass that check,
such as 000-000- or 123-456-6789.  That's why my example was a bit
more involved.

-- 

Network Infrastructure Manager
Documentation, Webmaster Teams
http://www.php.net/

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



[PHP-DB] Re: [PHP] Regex for telephone numbers

2010-12-30 Thread Ethan Rosenberg

At 07:27 PM 12/29/2010, Josh Kehn wrote:



On Dec 29, 2010, at 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-.

>
> Thanks.
>
> Ethan
>
> MySQL 5.1  PHP 5  Linux [Debian (sid)]
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

You can't, phone numbers are more complex then that. You could use 
\d{3}-\d{3}-\d{4} to match that basic pattern for all numbers though.


Regards,

-Josh
___
http://joshuakehn.com






Sent from my iPod

Josh -

I used use \d{3}-\d{3}-\d{4}.

It works beautifully!!

FYI [to all the list] -- I thank all for their input.  I only needed 
US phones, and I am forcing the user of the form to conform to 
xxx-xxx- as the input format.


Ethan




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



[PHP-DB] Re: [PHP] Regex for telephone numbers

2010-12-29 Thread Daniel P. Brown
On Wed, Dec 29, 2010 at 19:12, 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-.

Congrats.  People in Hell would like ice water.  Now we all know
that everyone wants something.  ;-P

Really, this isn't a PHP question, but rather one of regular
expressions.  That said, something like this (untested) should work:




-- 

Dedicated Servers, Cloud and Cloud Hybrid Solutions, VPS, Hosting
(866-) 725-4321
http://www.parasane.net/

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



Re: [PHP-DB] Re: [PHP] Regex for telephone numbers

2010-12-29 Thread Karl DeSaulniers

You could also help them out a little with something like..

$phone = str_replace("(", "", $phone);
$phone = str_replace(")", "-", $phone);

HTH,

Karl


On Dec 29, 2010, at 6:27 PM, Josh Kehn wrote:




On Dec 29, 2010, at 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-.


Thanks.

Ethan

MySQL 5.1  PHP 5  Linux [Debian (sid)]


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



You can't, phone numbers are more complex then that. You could use  
\d{3}-\d{3}-\d{4} to match that basic pattern for all numbers though.


Regards,

-Josh
___
http://joshuakehn.com
Sent from my iPod
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Karl DeSaulniers
Design Drumm
http://designdrumm.com


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



Re: [PHP-DB] Re: [PHP] Regex for telephone numbers

2010-12-29 Thread Karl DeSaulniers

Hi Ethan,
Could you do a string compare and check at certain characters for a  
dash?

IE:
check the second character to see if it is a dash for 1-800...
if that is not a dash, check the fourth character for a dash, 469-9...
then the other places  where dashes would be based on those two  
characters.
You may have to investigate how international numbers would work and  
adjust appropriately, but for the US, that should work.

Then just send an error message when it isn't like you want.
JAT

Karl


On Dec 29, 2010, at 6:27 PM, Josh Kehn wrote:




On Dec 29, 2010, at 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-.


Thanks.

Ethan

MySQL 5.1  PHP 5  Linux [Debian (sid)]


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



You can't, phone numbers are more complex then that. You could use  
\d{3}-\d{3}-\d{4} to match that basic pattern for all numbers though.


Regards,

-Josh
___
http://joshuakehn.com
Sent from my iPod
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Karl DeSaulniers
Design Drumm
http://designdrumm.com


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



[PHP-DB] Re: [PHP] Regex for telephone numbers

2010-12-29 Thread Josh Kehn


On Dec 29, 2010, at 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-.
> 
> Thanks.
> 
> Ethan
> 
> MySQL 5.1  PHP 5  Linux [Debian (sid)] 
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

You can't, phone numbers are more complex then that. You could use 
\d{3}-\d{3}-\d{4} to match that basic pattern for all numbers though.

Regards,

-Josh
___
http://joshuakehn.com
Sent from my iPod
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DB] RE: [PHP] Regex for telephone numbers

2010-12-29 Thread admin
Also remove your stupid Email filter.
If you need a email filter, you should not be on this list or learn to setup
rules one.


Richard L. Buskirk


-Original Message-
From: Ethan Rosenberg [mailto:eth...@earthlink.net] 
Sent: Wednesday, December 29, 2010 7:12 PM
To: php-db-lists.php.net; php-gene...@lists.php.net
Subject: [PHP] Regex for telephone numbers

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-.

Thanks.

Ethan

MySQL 5.1  PHP 5  Linux [Debian (sid)] 



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


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



[PHP-DB] Re: [PHP] Regex for telephone numbers

2010-12-29 Thread Simon J Welsh
On 30/12/2010, at 1: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-.
> 
> Thanks.
> 
> Ethan
> 
> MySQL 5.1  PHP 5  Linux [Debian (sid)] 
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

\d{3}-\d{3}-\d{4}

Also, have a look at the phoneNumber method in the relevant Validate PEAR 
package: http://pear.php.net/packages.php?catpid=50&catname=Validate

---
Simon Welsh
Admin of http://simon.geek.nz/

Who said Microsoft never created a bug-free program? The blue screen never, 
ever crashes!

http://www.thinkgeek.com/brain/gimme.cgi?wid=81d520e5e


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



[PHP-DB] RE: [PHP] Regex for telephone numbers

2010-12-29 Thread admin
I suggest you try javascript.



Richard L. Buskirk

-Original Message-
From: Ethan Rosenberg [mailto:eth...@earthlink.net] 
Sent: Wednesday, December 29, 2010 7:12 PM
To: php-db-lists.php.net; php-gene...@lists.php.net
Subject: [PHP] Regex for telephone numbers

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-.

Thanks.

Ethan

MySQL 5.1  PHP 5  Linux [Debian (sid)] 



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


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