Total members 10262 | Gratitudes |It is currently Wed May 23, 2012 8:34 pm Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 1 post ] 
Author Code Snippet
 Code subject: validate international phone number value
PostPosted: Wed Oct 26, 2011 12:17 am 
Offline
Mastermind
User avatar

Joined: Tue Mar 27, 2007 10:55 pm
Posts: 2279
Location: Earth
Has thanked: 39 time
Have thanks: 61 time

Check an international phone number using JavaScript.

Code:
var digits "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars phoneNumberDelimiters "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber 6;

function checkInternationalPhone(strPhone){
var bracket=3

if(strPhone.indexOf("+")>1) return false
if(strPhone.indexOf("-")!=-1)bracket=bracket+1
if(strPhone.indexOf("(")!=-&& strPhone.indexOf("(")>bracket)return false
var brchr
=strPhone.indexOf("(")
if(
strPhone.indexOf("(")!=-&& strPhone.charAt(brchr+2)!=")")return false
if(strPhone.indexOf("(")==-&& strPhone.indexOf(")")!=-1)return false
s
=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}
 

Code:
function stripCharsInBag(sbag)
{   var 
i;
    var 
returnString "";
    
// Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    
for (0s.lengthi++)
    {   
        
// Check that current character isn't whitespace.
        
var s.charAt(i);
        if (
bag.indexOf(c) == -1returnString += c;
    }
    return 
returnString;
}
 


Code:
function isInteger(s)
{   var 
i;
    for (
0s.lengthi++)
    {   
        
// Check that current character is number.
        
var s.charAt(i);
        if (((
"0") || ("9"))) return false;
    }
    
// All characters are numbers.
    
return true;
}
 

_________________
Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )


TOP
 Profile Send private message  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 1 post ] 
Quick reply


  

 Similar topics
 Application of Cell Phone Jammer
 ordered list from specific number
 Communication from pc to cell phone
 PHP Phone Book
 increase the number of bank lines by <br/>
 I download the phone book coding from your site
 validate age entered as selection box in javascript
 Factor of number using C++ code
 how to build cell phone app
 how to make an application in java for cell phone.

All times are UTC [ DST ]


Users browsing similar codes

Users browsing this forum: No registered users and 1 guest



Jump to:  
Previous Code Snippet | Next Code Snippet 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team