Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

simple if condition for form validation

const signup=()=>{
    let name=document.querySelector("#u_name").value;
    let email=document.querySelector("#email_id").value;
    let password=document.querySelector("#pwd").value;
    let confirmPassword=document.querySelector("#confirm_pwd").value;
    let i=0;
    if((name==""||email=="")||(password==""||confirmPassword==""))
    {
        document.querySelector("#empty-field").innerHTML="*Fill all required fields";
        i++;
    }
    else
    {
    if(name.length<3)
    {
        document.querySelector("#u_name").style.borderColor="red";
        document.querySelector("#user-errmsg").innerHTML="*Enter valid user name";
        i++;
    }
    else
    {
        document.querySelector("#u_name").style.borderColor="#ced4da";
        document.querySelector("#user-errmsg").innerHTML="";
        i;
    }
    if(email.length<6)
    {
        document.querySelector("#email_id").style.borderColor="red";
        document.querySelector("#email-errmsg").innerHTML="*Enter valid email id";
        i++;
    }
    else
    {
        document.querySelector("#email_id").style.borderColor="#ced4da";
        document.querySelector("#email-errmsg").innerHTML="";
        i;
    }
    if(password.length<6 && confirmPassword.length<6)
    {
        document.querySelector("#pwd").style.borderColor="red";
        document.querySelector("#confirm_pwd").style.borderColor="red";
        document.querySelector("#pwd-errmsg").innerHTML="*Password must be atleast 6 digits long";
        i++;
    }
    else if(password.length<6 && confirmPassword.length>=6)
    {
        document.querySelector("#confirm_pwd").style.borderColor="red";
        document.querySelector("#pwd").style.borderColor="red";
        document.querySelector("#pwd-errmsg").innerHTML="*Password must be atleast 6 digits long";
        i++;
    }
    else if(password.length>=6 && confirmPassword.length>=6)
        {
            if(password!= confirmPassword)
            {
                document.querySelector("#pwd").style.borderColor="red";
                document.querySelector("#confirm_pwd").style.borderColor="red";
                document.querySelector("#pwd-errmsg").innerHTML="*Both fields must have the same password";
                i++;
            }
            else
            {
                document.querySelector("#pwd").style.borderColor="#ced4da";
                document.querySelector("#confirm_pwd").style.borderColor="#ced4da";
                document.querySelector("#pwd-errmsg").innerHTML="";
                i;
            }
        }
    else
    {
        document.querySelector("#pwd").style.borderColor="red";
        document.querySelector("#confirm_pwd").style.borderColor="red";
        document.querySelector("#pwd-errmsg").innerHTML="*Both fields must have the same password";
        i++;
    }
    document.querySelector("#empty-field").innerHTML="";
    }
    if(i==0)
    return true;
    else
    return false
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: unslick if more then 
Javascript :: react native gridient button 
Javascript :: include antoher file wagger 
Javascript :: js palindrome number 
Javascript :: how to set direction based on language in angular 
Javascript :: telerik grid data automatically scroll to particular record in react 
Javascript :: vs 2019 how to publish angular environment prod 
Javascript :: tskill nodejs port 
Javascript :: Pure JavaScript Send POST NO JQUERY 
Javascript :: javascript asdyn function 
Javascript :: cheatsheet addeventlistener 
Javascript :: Run a second function only after the first function is completely finished 
Javascript :: kjkjl 
Javascript :: ex:javascript array 
Javascript :: como saber cuando un link cambia angular 
Javascript :: select elements of an array starting by a vowel 
Javascript :: npm can i use my modules without specifying the path 
Javascript :: how to connect next js with postgresql localhost 
Javascript :: wow uh dk makros 9.01 
Javascript :: react enzyme mount ReferenceError: is not defined 
Javascript :: math.random and clone 
Javascript :: How can I display an image and text from an array on a webpage? Ask Question 
Javascript :: onswitch from tab do something jquery 
Javascript :: js go to see history 
Javascript :: purecomponent re rendering 
Javascript :: cortar elemento y pegar en otro lugar jquery 
Javascript :: angular stepper change wait before changing 
Javascript :: set up chrome dev tools adonisjs 
Javascript :: How to pass a map from controller to javascript function in VF page 
Javascript :: how enable custom css and js vscode ubuntu 
ADD CONTENT
Topic
Content
Source link
Name
8+9 =