jcadima
2/16/2016 - 3:50 PM

Validate Area Code

Validate Area Code

function validateForm_modal() {
  var fname  = document.forms["homeform_modal"]["FirstName"].value;
	var lname  = document.forms["homeform_modal"]["LastName"].value;
	// this
	var mobile = document.forms["homeform_modal"]["MobilePhone"].value;
	
	//  EMPTY MOBILE NUMBER
    else if (mobile == null || mobile == "" ) {

       sweetAlert("Oops!", "We need your phone number to verify your identity.", "error");
        return false;
    }	
    
    // INVALID MOBILE NUMBER
    else if ( validareacode(mobile) == false ) {

       sweetAlert("Invalid Entry!", "The number you entered is invalid.  Please check the number and try again.  If the problem persists, please contact our Concierge at 844-476-2786.", "error");
        return false;
    }	

	
}	



function validareacode(mobile) { 
//US Invalid Area Codes
var result = true;
var AreaCode=new Array(204,211,226,236,242,246,249,250,264,268,284,306,340,343,345,365,387,403,411,416,418,431,437,438,441,450,456,457,473,500,506,511,514,519,521,522,523,524,525,526,527,528,529,532,533,535,538,542,550,552,553,554,555,556,558,566,577,578,579,581,587,588,589,600,604,611,613,639,647,649,664,670,671,672,684,700,705,709,710,711,721,742,758,767,778,780,782,784,787,800,807,809,811,819,822,825,829,833,844,849,855,866,867,868,869,873,876,877,880,881,882,883,884,885,886,887,888,889,900,902,905,911,939,950);
    
    //var mobile = document.forms["homeform"]["mobile"].value;  //  (305)-123-4567
    var code   = mobile.substring(1, 4);  //  305
    console.log("CODE: " + code);
    var code_npa = mobile.substring(1,4);  // 000 - 200
    console.log("CODE_NPA: " + code_npa);
    var area_code = parseInt(code_npa);
    console.log("AREA_CODE: " + area_code);
    var nxx_n = mobile.substring(6,7) ;   // 1
    console.log("NXX_N: " + nxx_n);
	var nxx_xx = mobile.substring(7,9) ;  // 23
	console.log("NXX_XX: " + nxx_xx);
	
    var length = AreaCode.length;  // array length
    for (var i = 0; i < length; i++) {
        if(AreaCode[i] == code ) { result = false; }
    }
	
	if ( area_code >= 0 && area_code <= 200 ) { result = false ;}
	if ( nxx_n == 1 ) { result = false ;}
	if ( nxx_xx == 11 ) { result = false ;}
		

    return result;
}