[Solved] javascript terms for functions for registration form


What you will want to do is have each function return a Boolean based on is the values for that item are invalid or valid. For invalid input return false and for valid input return true. Here is a simple example with two functions:

function validateOne() {
    if( /* Input for validateOne is valid */ )
        return true
    else
        return false
}

function validateTwo() {
    if( /* Input for validateTwo is valid */ )
        return true
    else
        return false
}

if(validateOne() && validateTwo()) {
    // Everything is valid, move to registration complete webpage
} else {
    // Not everything is valid
}

Here a real example using the concepts above for verifying say a username and a password. Where (for simplicity) the username cannot be empty and the password cannot be empty and needs to be more than 5 characters. Your program overall will be a little more complex from this.

function validateUsername() {
    // When there is at least a single character entered
    var username = register.Username.value;
    if( username.length > 0 ) 
        return true; // than the username is valid
    else
        return false; // otherwise not valid
}

function validatePassword() {
    // When the length of the password is over 5
    var password = register.password.value; 
    if( password.length > 5 )
        return true; // than the password is valid
    else
        return false; // otherwise not valid
}

if(validateUsername() && validatePassword()) {
    // Everything is valid, move to registration complete webpage
} else {
    // Not everything is valid
}

To get you started here is how your first Username function would look:

function UserName()
{
    var User = register.Username.value;
    //var i; <- You don't need this

    if (User.length == 0) { // cannot be empty -> false
        alert("Please Enter First name");
        return false;
    }
    else if (User.length < 6) { // Needs more than 6 characters -> false
        alert("your name most have a minimum of 6 digits/charachters"); 
        return false;
    }
    else { // Has more than 6 characters -> true
        return true;
   }      
}

7

solved javascript terms for functions for registration form