Created
          June 26, 2012 17:36 
        
      - 
      
 - 
        
Save computercarguy/2997308 to your computer and use it in GitHub Desktop.  
    JavaScript phone number validation
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | function FormatPhone(ThePhone){ | |
| if (ThePhone.length >= 9){ | |
| ThePhone = ThePhone.replace(/\(/gi,""); | |
| ThePhone = ThePhone.replace(/\)/gi,""); | |
| ThePhone = ThePhone.replace(/-/gi,""); | |
| ThePhone = ThePhone.replace(/\ /gi,""); | |
| return ThePhone; | |
| } else { | |
| return "invalid"; | |
| } } | |
| function NoChrs(Field){ | |
| ChangedPage = true; | |
| AllowedChrs = ""; | |
| if (Field == "Phone"){ | |
| AllowedChrs = "().-"; | |
| } | |
| tempArr = document.getElementById(Field).value.split(""); | |
| for (i=0;i<tempArr.length;i++){ | |
| if ((isNaN(parseFloat(tempArr[i]))) && (AllowedChrs.indexOf(tempArr[i]) == -1)){ | |
| tempArr[i] = ""; | |
| } } | |
| document.getElementById(Field).value = tempArr.join(""); | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment