Re: [PHP] Regex for telephone numbers

2010-12-31 Thread Nathan Rixham

Ethan Rosenberg wrote:
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.


out of interest, why are you forcing you're users to conform to that 
input format? you could simply strip all non-numeric chars then format 
how you like to save, thus giving users a looser, more friendly, experience.


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



Re: [PHP] Regex for telephone numbers

2010-12-31 Thread Ethan Rosenberg

At 07:11 AM 12/31/2010, Nathan Rixham wrote:

Ethan Rosenberg wrote:
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.


out of interest, why are you forcing you're users to conform to that 
input format? you could simply strip all non-numeric chars then 
format how you like to save, thus giving users a looser, more 
friendly, experience.

+
Nathan -

This expression will be used to search a database which will contain 
patient data resulting from medical research.  At the initial visit a 
medical record number will be assigned to the patient.  Other 
information will be collected at that point; eg,  the telephone 
number. At subsequent visits, the patient will be referenced by 
his/hers medical record number.  If the patient either forgot their 
clinic card, or cannot remember their medical record number, a search 
will be performed.  One of the many parameters that can be used in 
the search is the phone number. It is easier if all the data has a 
fixed format.  The form for  the initial visit will use a regex that 
will validate the phone number. As  the research will be performed in 
the US, only US numbers have to be validated.


Hope this helps.

Ethan




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



Re: [PHP] Regex for telephone numbers

2010-12-31 Thread a...@ashleysheridan.co.uk
Sorry for top-post, on phone.

What about mobile phone numbers (cell phones you call them in the US) do they 
conform to the same format? I know there have been times myself when I've been 
without a landline number leaving me with only my mobile as a means of contact.

Thanks,
Ash
http://www.ashleysheridan.co.uk

- Reply message -
From: Ethan Rosenberg eth...@earthlink.net
Date: Fri, Dec 31, 2010 14:03
Subject: [PHP] Regex for telephone numbers
To: Nathan Rixham nrix...@gmail.com
Cc: php-general@lists.php.net php-general@lists.php.net


At 07:11 AM 12/31/2010, Nathan Rixham wrote:
Ethan Rosenberg wrote:
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.

out of interest, why are you forcing you're users to conform to that 
input format? you could simply strip all non-numeric chars then 
format how you like to save, thus giving users a looser, more 
friendly, experience.
+
Nathan -

This expression will be used to search a database which will contain 
patient data resulting from medical research.  At the initial visit a 
medical record number will be assigned to the patient.  Other 
information will be collected at that point; eg,  the telephone 
number. At subsequent visits, the patient will be referenced by 
his/hers medical record number.  If the patient either forgot their 
clinic card, or cannot remember their medical record number, a search 
will be performed.  One of the many parameters that can be used in 
the search is the phone number. It is easier if all the data has a 
fixed format.  The form for  the initial visit will use a regex that 
will validate the phone number. As  the research will be performed in 
the US, only US numbers have to be validated.

Hope this helps.

Ethan




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



Re: [PHP] Regex for telephone numbers

2010-12-31 Thread Ethan Rosenberg

At 09:27 AM 12/31/2010, a...@ashleysheridan.co.uk wrote:

Sorry for top-post, on phone.

What about mobile phone numbers (cell phones you call them in the 
US) do they conform to the same format? I know there have been times 
myself when I've been without a landline number leaving me with only 
my mobile as a means of contact.


Thanks,
Ash
http://www.ashleysheridan.co.ukhttp://www.ashleysheridan.co.uk

- Reply message -
From: Ethan Rosenberg eth...@earthlink.net
Date: Fri, Dec 31, 2010 14:03
Subject: [PHP] Regex for telephone numbers
To: Nathan Rixham nrix...@gmail.com
Cc: php-general@lists.php.net php-general@lists.php.net


At 07:11 AM 12/31/2010, Nathan Rixham wrote:
Ethan Rosenberg wrote:
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.

out of interest, why are you forcing you're users to conform to that
input format? you could simply strip all non-numeric chars then
format how you like to save, thus giving users a looser, more
friendly, experience.
+
Nathan -

This expression will be used to search a database which will contain
patient data resulting from medical research.  At the initial visit a
medical record number will be assigned to the patient.  Other
information will be collected at that point; eg,  the telephone
number. At subsequent visits, the patient will be referenced by
his/hers medical record number.  If the patient either forgot their
clinic card, or cannot remember their medical record number, a search
will be performed.  One of the many parameters that can be used in
the search is the phone number. It is easier if all the data has a
fixed format.  The form for  the initial visit will use a regex that
will validate the phone number. As  the research will be performed in
the US, only US numbers have to be validated.

Hope this helps.

Ethan




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





Ash -

In contrast to some non-US phone numbers, all the numbers here [cell 
and landline] have the same format.


Ethan 




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



Re: [PHP] Regex for telephone numbers

2010-12-31 Thread Nathan Rixham

Ethan Rosenberg wrote:

At 07:11 AM 12/31/2010, Nathan Rixham wrote:

Ethan Rosenberg wrote:
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.


out of interest, why are you forcing you're users to conform to that 
input format? you could simply strip all non-numeric chars then format 
how you like to save, thus giving users a looser, more friendly, 
experience.

+
Nathan -

This expression will be used to search a database which will contain 
patient data resulting from medical research.  At the initial visit a 
medical record number will be assigned to the patient.  Other 
information will be collected at that point; eg,  the telephone number. 
At subsequent visits, the patient will be referenced by his/hers medical 
record number.  If the patient either forgot their clinic card, or 
cannot remember their medical record number, a search will be 
performed.  One of the many parameters that can be used in the search is 
the phone number. It is easier if all the data has a fixed format.  The 
form for  the initial visit will use a regex that will validate the 
phone number. As  the research will be performed in the US, only US 
numbers have to be validated.


Ethan,

I think you misunderstand, I'm saying that regardless of which format 
you use within the system, users could enter phone numbers as 
1231231234 123 123 1234 123-123 1234 or any variant they like, 
that's completely orthogonal to how you validate and save the data, in 
all of those cases all you need to do string non-numeric chars to 
validate, you may also find your indexes work that bit quicker storing 
numbers rather than specially (and needlessly) formatted string.


Likewise on the way back out, when presenting the numbers to users, all 
you need to do is string format them.


Follow?


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



Re: [PHP] Regex for telephone numbers

2010-12-31 Thread Per Jessen
a...@ashleysheridan.co.uk wrote:

 Sorry for top-post, on phone.
 
 What about mobile phone numbers (cell phones you call them in the US)
 do they conform to the same format? 

AFAIK, they too vary from country to country.  Swiss mobile numbers are
07[6789] NNN, the latter usually written as NNN NN NN, but also
often in a way that will help remembering the number.  
Danish mobile#s are the same as land line numbers, no area code, just
. 



-- 
Per Jessen, Zürich (2.8°C)


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



Re: [PHP] Regex for telephone numbers

2010-12-31 Thread Daniel P. Brown
On Fri, Dec 31, 2010 at 11:04, Per Jessen p...@computer.org wrote:

 AFAIK, they too vary from country to country.  Swiss mobile numbers are
 07[6789] NNN, the latter usually written as NNN NN NN, but also
 often in a way that will help remembering the number.
 Danish mobile#s are the same as land line numbers, no area code, just
 .

In the US and Canada, though, there's [as of yet] no difference
between landline, mobile, VOIP, fax, toll-free, premium (900), et
cetera.  Again, that's why I wrote out the example the way I did,
which conforms to NANP (NPA/NXX) standards.  It's the only suggestion
so far that will work completely (which sounds cocky, but screw it,
it's the last Friday of the year  ;-P).

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

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



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 eth...@earthlink.netwrote:

 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] Regex for telephone numbers

2010-12-31 Thread Daniel Brown
On Fri, Dec 31, 2010 at 12:05, Dmitriy Ugnichenko
mitya.ugniche...@gmail.com 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.

-- 
/Daniel P. Brown
Network Infrastructure Manager
Documentation, Webmaster Teams
http://www.php.net/

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



Re: [PHP] Regex for telephone numbers

2010-12-31 Thread Steve Staples
On Wed, 2010-12-29 at 19:35 -0500, Daniel P. Brown wrote:
 On Wed, Dec 29, 2010 at 19:12, Ethan Rosenberg eth...@earthlink.net 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:
 
 ?php
 
 $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;
 }
 ?
 
 THIS 
is the regex you want to use... it is the most complete one that has
been posted here, and it works.


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



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 eth...@earthlink.net 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:
 
 ?php
 
 $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 General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regex for telephone numbers

2010-12-31 Thread Daniel P. Brown
On Fri, Dec 31, 2010 at 19:09, Jim Lucas li...@cmsws.com 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.

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

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



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 eth...@earthlink.net 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 General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] 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 eth...@earthlink.net 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.

-- 
/Daniel P. Brown
Network Infrastructure Manager
Documentation, Webmaster Teams
http://www.php.net/

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



Re: [PHP] Regex for telephone numbers

2010-12-30 Thread Tamara Temple


On Dec 29, 2010, at 6:12 PM, Ethan Rosenberg wrote:

I would like to have a regex  which would validate that a telephone  
number is in the format xxx-xxx-.




http://lmgtfy.com/?q=regex+to+validate+US+phone+numbers

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



[PHP] Regex for telephone numbers

2010-12-29 Thread Ethan Rosenberg

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



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-general@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 General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



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=50catname=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 General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



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-general@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 General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regex for telephone numbers

2010-12-29 Thread Josh Kehn


On Dec 29, 2010, at 7:12 PM, Ethan Rosenberg eth...@earthlink.net 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 General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[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 eth...@earthlink.net  
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 General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[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 eth...@earthlink.net  
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 General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



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

2010-12-29 Thread Alexis
Why not have three separate fields for each part, as that way you don't 
need to bother about how the user separates them, as trust me, if they 
can break it, they will.
I have found it is best to always limit the amount of free entry you 
permit a user, as that will drastically cut back in data entry validation.


Alexis


On 29/12/10 17:46, Karl DeSaulniers wrote:

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 eth...@earthlink.net
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 General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regex for telephone numbers

2010-12-29 Thread Daniel P. Brown
On Wed, Dec 29, 2010 at 19:12, Ethan Rosenberg eth...@earthlink.net 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:

?php

$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;
}
?


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

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