Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Javascript validate email

function validateEmail($email) {
  var emailReg = /^([w-.]+@([w-]+.)+[w-]{2,4})?$/;
  return emailReg.test( $email );
}

if( !validateEmail(emailaddress)) { /* do stuff here */ }
Comment

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');
});
Comment

validate email or phone js

    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 or 8801710336617
        var re = /^(?:(?:+|00)88|01)?d{11}$/;
        return re.test(phone);
    }

    function validate() {

        document.getElementById('email_error').innerHTML = "";
        field = $('#email_phone').val();
        //If not an email AND not a phone
        if (validateEmail(field)) {
            //alert('Email Passed');
            //onChange();
            document.getElementById('email').value = document.getElementById('email_phone').value;
            document.getElementById('phone').value = "";
            //return true;
        } else if (validatePhone(field)) {
            //alert('Phone Passed');
            document.getElementById('phone').value = document.getElementById('email_phone').value;
            document.getElementById('email').value = "";
            //return true;
        } else {
            //alert('Email or Phone Error');
            document.getElementById('email').value = "";
            document.getElementById('phone').value = "";
            let text;
            text = "<strong><span style='color:red'> Email or Phone number Invalid</span></strong>";
            document.getElementById("email_error").innerHTML = text;
            return false;
        }

        // Password Match
        var password = document.getElementById('password').value;
        var confirm_password = document.getElementById('password_confirm').value;

        document.getElementById("password_error").innerHTML="";
        if(password==""){
            document.getElementById("password_error").innerHTML="Please enter password";
            return false;   
        }

        if (password != confirm_password) {
            let text1;
            text1 ="<strong><span style='color:red'>The password and its confirm are not the same </span></strong>";
            document.getElementById("password_match").innerHTML = text1;
            return false;
        }

            // Clear Email field value if change
            $("#email_phone").change(function() {
                document.getElementById('email').value = "";
            });
            // Clear Phone field value if change
            $("#email_phone").change(function() {
                document.getElementById('phone').value = "";
            });
            $("#email_phone").change(function() {
                document.getElementById('password_error').value = "";
            });

    }
Comment

PREVIOUS NEXT
Code Example
Javascript :: Find the next perfect square! 
Javascript :: get current store id magento 2 
Javascript :: jquery each hover 
Javascript :: truncate string in javascript 
Javascript :: path.join nodejs 
Javascript :: check if object is not defined js 
Javascript :: how to compare two arrays javascript 
Javascript :: body parser deprecated 
Javascript :: multiple checkbox validation in jquery 
Javascript :: javascript capitalize all letters 
Javascript :: how to open a new browser window using a .bat 
Javascript :: new blob javascript 
Javascript :: react big calendar event color 
Javascript :: javascript shift everything in array to the right 
Javascript :: media queries generator script 
Javascript :: video mute and unmute 
Javascript :: javascript design patterns pdf 
Javascript :: node js send javascript 
Javascript :: declare function javascript 
Javascript :: how to destructure props in react 
Javascript :: alert 
Javascript :: js remove key from object 
Javascript :: jest Your test suite must contain at least one test. 
Javascript :: using underscore javascript number 
Javascript :: execcommand javascript 
Javascript :: javascript promise.all 
Javascript :: yarn add next auth 
Javascript :: javascript copy value to clipboard 
Javascript :: what is side effect 
Javascript :: react native dotenv 
ADD CONTENT
Topic
Content
Source link
Name
7+1 =