alex's solution to "Super Robust Phone Number Validation in Javascript"

I am unsure as what exactly you are looking for, but I belive these functions below might work. All you have to do is to run the string through the function. The first function `numbersOnly` will take any string and remove all non-number characters. The second function will do the same but also will only accept the first 15 characters (because the [E.164](http://en.wikipedia.org/wiki/E.164) recommendation for phone numbers only allows 15 characters). The third function does what the second function does but also adds the `+` infront of the numbers. function numbersOnly(string) { return(string.replace(/[^0-9]/g, '')); } function numberLength(string) { return(string.replace(/[^0-9]/g, '').substring(0,15)) } )); } function numberPlus(string) { return('+'+string.replace(/[^0-9]/g, '').substring(0,15)) })); }
I am unsure as what exactly you are looking for, but I belive these functions below might work. All you have to do is to run the string through the function. The first function `numbersOnly` will take any string and remove all non-number characters. The second function will do the same but also will only accept the first 15 characters (because the [E.164](http://en.wikipedia.org/wiki/E.164) recommendation for phone numbers only allows 15 characters). The third function does what the second function does but also adds the `+` infront of the numbers. function numbersOnly(string) { return(string.replace(/[^0-9]/g, '')); } , '')); } // 1a234d5-6f7g8(901[]2)3/456 => 1234567890123456 function numberLength(string) { return(string.replace(/[^0-9]/g, '').substring(0,15)); } )); } // 1a234d5-6f7g8(901[]2)3/456 => 123456789012345 function numberPlus(string) { return('+'+string.replace(/[^0-9]/g, '').substring(0,15)); })); } // 1a234d5-6f7g8(901[]2)3/456 => +123456789012345
I am unsure as what exactly you are looking for, but I belive these functions below might work. All you have to do is to run the string through the function. The first function `numbersOnly` will take any string and remove all non-number characters. The second function will do the same but also will only accept the first 15 characters (because the [E.164](http://en.wikipedia.org/wiki/E.164) recommendation for phone numbers only allows 15 characters). The third function does what the second function does but also adds the `+` infront of the numbers. function numbersOnly(string) { return(string.replace(/[^0-9]/g, '')); } // 1a234d5-6f7g8(901[]2)3/456 => 1234567890123456 function numberLength(string) { return(string.replace(/[^0-9]/g, '').substring(0,15)); } // 1a234d5-6f7g8(901[]2)3/456 => 123456789012345 function numberPlus(string) { return('+'+string.replace(/[^0-9]/g, '').substring(0,15)); } // 1a234d5-6f7g8(901[]2)3/456 => +123456789012345 function formatNumberUS(string) { var string = string.replace(/[^0-9]/g, '').substring(0,10); var first3 = string.substring(0,3); var next3 = string.substring(3,6); var next4 = string.substring(6,10); return("+1("+first3+") "+next3+"-"+next4); } //9\[[a0[]]a0+as84dasd,,<>61sdf6as41 => +1(900) 846-1641

User: alex

Question: Super Robust Phone Number Validation in Javascript

Back to question