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

js email validation

if(value.match( /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:.[a-zA-Z0-9-]+)*$/gi)){
//code here
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: node js function infinite parameters 
Javascript :: find duplicates and their count in an array javascript 
Javascript :: fontawesome icon size 1.5 angular 
Javascript :: react-native-google-places-autocomplete only cities 
Javascript :: angularjs onclick disable button click 
Javascript :: setstate array 
Javascript :: vue 3 create app 
Javascript :: how to find last occurrence comma in a string and replace with value in javascript 
Javascript :: vue js use component everywhere 
Javascript :: ajax is not a function 
Javascript :: hello world program in javascript 
Javascript :: javascript access ajax response headers 
Javascript :: Flatten a multidimension array 
Javascript :: delete element of array javascript 
Javascript :: tolocale string no seconds 
Javascript :: check if every value in array is equal 
Javascript :: javascript for...of with Arrays 
Javascript :: javascript array.from 
Javascript :: mongoose user model example 
Javascript :: html anchor tag javascript confirm 
Javascript :: compare date and time in js 
Javascript :: jquery multiple ids same funjquery apply function to multiple elementsction 
Javascript :: fetch data with axios in reactjs 
Javascript :: p5js left mouse click 
Javascript :: remove trailing zeros javascript 
Javascript :: vue computed 
Javascript :: Get Keys Of JSON As Array 
Javascript :: javascript select from array where 
Javascript :: remove duplicates in array 
Javascript :: card type through card number 
ADD CONTENT
Topic
Content
Source link
Name
6+6 =