Total members 11895 |It is currently Thu Dec 26, 2024 11:01 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





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




_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : validate international phone number value
 Now Hiring International Data Entry Typists     -  
 convert integer number to octal,hexadecimal number systems     -  
 validate username     -  
 validate mail in jsp     -  
 validate e-mail in php     -  
 validate domain name in php     -  
 convert octal number to decimal number     -  
 convert decimal number to octal number     -  
 validate email address in asp     -  
 validate age entered as selection box in javascript     -  



Topic Tags

JavaScript Validation
cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com