Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Validate email or phone number javascript

function validateEmail(email) 
{
     var re = /^(([^<>()[].,;:s@"]+(.[^<>()[].,;:s@"]+)*)|(".+"))@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}])|(([a-zA-Z-0-9]+.)+[a-zA-Z]{2,}))$/;
     return re.test(email);
}

function validatePhone(phone)
{
  // 880-1710-336617
  var re = /^(?(d{3}))?[- ]?(d{4})[- ]?(d{6})$/;
  return re.test(phone);
}


$('#button').click(function(){
    field = $('#email').val();
     
    //If not an email AND not a phone
    if(validateEmail(field))
    {
        alert('Email Passed');
        //show_error_msg('error_signup_email','Enter a valid email address or a phone number');   
        //jQuery("#signup_email").focus();
        return true;
    } else if (validatePhone(field)){
        alert('Phone Passed');
        return true;
    }
    else alert('Email or Phone Error');
});
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #Validate #email #phone #number #javascript
ADD COMMENT
Topic
Name
2+8 =