Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

regexing phone numbers 2

Status
Not open for further replies.

pushyr

Programmer
Jul 2, 2007
159
GB
ok, here's another little problem that i have....

there are three types of numbers i'm trying to match...

07912123456
07912 123456
07912-123456

here's my regex...

Code:
'#([0-9]{10,14})|([0-9]{5})\s([0-9]{4,7})#'

([0-9]{10,14}) works fine for this number format 07912123456

but for the other two numbers separated by a space or dash, this part of my regex is not working ([0-9]{5})\s([0-9]{4,7})
 
Hi

Would not be simpler like this ?
Code:
[gray]#[/gray] [red]07912[/red][blue]123456[/blue]
[gray]#[/gray] [red]07912[/red][highlight green] [/highlight][blue]123456[/blue]
[gray]#[/gray] [red]07912[/red][green]-[/green][blue]123456[/blue]

'#^[red][0-9]{5}[/red][green][ -]?[/green][blue][0-9]{6}[/blue]4#'

Feherke.
 
hi feherke,

i did exactly what you told me but it didn't work. here's my code...

Code:
preg_match('#^[0-9]{5}[ -]?[0-9]{6}4#', $PageArray0, $matched_telephone0);
$matched_telephone = $matched_telephone0[1];

here's an example of a string that im trying to match...

Code:
Contact telephone number: 07912 123456</span></strong></address><address><strong>website:</strong> <a href="[URL unfurl="true"]http://www.mysite.com/"[/URL] target="_blank">[URL unfurl="true"]www.mysite.com</a>[/URL] </address></td>
 
[tt]preg_match('[highlight]#[[/highlight]0-9]{5}[ -]?[0-9]{6[highlight]}#[/highlight]', $PageArray0, $matched_telephone0);
$matched_telephone = $matched_telephone0[[red]0[/red]];[/tt]
 
Hi

Oops, there was a typo. The "4" was intended to be "$".

From your first post I understood that you want to do kind of [tt]form[/tt] validation.

Anyway, see tsuji's code.

( Just a hint. To describe this kind of job in other threads the word "extract" was used instead of "match". Apparently with more success. )

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top