$('#name').keyup(function (){
    nameValidation();
});

function nameValidation()
{
    var nameValue = $('#name').val();
    var regex = /^[a-zA-Z-. ]{2,20}$/;
    if (regex.test(nameValue))
    {
        $('#nameError').text(' ');
        return true;
    }
    else
    {
        $('#nameError').text('Name field is not valid.');
        return false;
    }
}


$('#email').keyup(function (){
    emailValidation();
});

function emailValidation()
{
    var emailValue = $('#email').val();
    var regex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,3}$/;
    if (regex.test(emailValue))
    {
        $('#emailError').text(' ');
        return true;
    }
    else
    {
        $('#emailError').text('Email is not valid.');
        return false;
    }
}

$('#mobile').keyup(function (){
    mobileValidation();
});

function mobileValidation()
{
    var mobileValue = $('#mobile').val();
    var regex =  /(^(\+8801|8801|01|008801))[1|3-9]{1}(\d){8}$/;
    if (regex.test(mobileValue))
    {
        $('#mobileError').text(' ');
        return true;
    }
    else
    {
        $('#mobileError').text('Mobile number is not valid.');
        return false;
    }
}

$('#password').keyup(function (){
    passwordValidation();
});

function passwordValidation()
{
    var passwordValue = $('#password').val();
    if (passwordValue.length >= 6)
    {
        $('#passwordError').text(' ');
        return true;
    }
    else
    {
        $('#passwordError').text('Password is not valid.');
        return false;
    }
}


$('#showHide').click(function (){
    if ($(this).is(':checked')) {
        $('#password').attr('type', 'text');
    } else {
        $('#password').attr('type', 'password');
    }
});


$('#confirmPassword').keyup(function (){
    confirmPasswordValidation();
});

function confirmPasswordValidation()
{
    var passwordValue = $('#password').val();
    var confirmPasswordValue = $('#confirmPassword').val();
    if (passwordValue == confirmPasswordValue)
    {
        $('#confirmPasswordError').text(' ');
        return true;
    }
    else
    {
        $('#confirmPasswordError').text('Password and confirm password are not same.');
        return false;
    }
}



$('#registrationForm').submit(function () {
    nameValidation();
    emailValidation();
    mobileValidation();
    passwordValidation();
    confirmPasswordValidation();

    if (nameValidation() == true && emailValidation() == true && mobileValidation() == true && passwordValidation() == true && confirmPasswordValidation() == true)
    {
        return true
    }
    return false;
});