Reply
Phone number check
Old 11-12-2004, 09:25 AM Phone number check
Junior Talker

Posts: 1
I am in need of some software, database or coding to check phone numbers which are entered into a form. These check is to verify that number exists etc.
prestick is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 11-12-2004, 12:38 PM
foobar's Avatar
Extreme Talker

Posts: 225
I don't think you can verify if a number exists. You can, howver, make sure that was is entered is a valid number (and not just random characters). By valid, I leam formatted correctly. This can be done using Regular Expressions.
foobar is offline
Reply With Quote
View Public Profile Visit foobar's homepage!
 
Old 11-12-2004, 01:10 PM
Republikin's Avatar
Super Moderator

Posts: 3,191
here is a regex for matching us phone numbers...

Code:
^(?:(?<1>[(])?(?<AreaCode>[2-9]\d{2})(?(1)[)])(?(1)(?<2>[ ])
|(?:(?<3>[-])|(?<4>[ ])))?)?(?<Prefix>[1-9]\d{2})(?(AreaCode
)(?:(?(1)(?(2)[- ]|[-]?))|(?(3)[-])|(?(4)[- ]))|[- ]?)(?<Suf
fix>\d{4})$
Matches:
333-4444 | 222 333 4444 | (222) 333-4444

Non-Matches:
222333 4444 | 222-333 4444 | (222)-333 4444

http://regexlib.com/REDetails.aspx?regexp_id=536
Republikin is offline
Reply With Quote
View Public Profile
 
Old 11-12-2004, 01:36 PM
NateDogg's Avatar
Extreme Talker

Posts: 163
I agree with Foobar that you can't check to see if the actaully is hooked up. You can only check to see if it is valid.

I would suggest client side checking rather than server side as it saves server time.
I'd use some JavaScript functions. With 3 or possibly 4 html textboxes (1 for areacode, 1 for the prefix and 1 for the suffix, maybe one for extention) You'd just need to check if they're numeric.

I'll post some code later.
__________________
Nathan

Become an affiliate
Web Design Web Hosting
NateDogg is offline
Reply With Quote
View Public Profile
 
Old 11-12-2004, 03:16 PM
Republikin's Avatar
Super Moderator

Posts: 3,191
Personaly I would stay away from client side scripting as there are a few users who turn off JavaScript. Something like the regex above would not put that much of a strain on the server to be of any significant difference.

Here is how I would do it with php...

PHP Code:
$strMatch ereg('^(?:(?<1>[(])?(?<AreaCode>[2-9]\d{2})(?(1)[)])(?(1)(?<2>[])|(?:(?<3>[-])|(?<4>[])))?)?(?<Prefix>[1-9]\d{2})(?(AreaCode)(?:(?(1)(?(2)[-]|[-]?))|(?(3)[-])|(?(4)[-]))|[-]?)(?<Suffix>\d{4})$'$_POST['phone_number']);

if(
$strMatch) {
    
// It matched, do something here
}else{
    
// It did not match

Republikin is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Phone number check
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.12359 seconds with 12 queries