﻿function Password_ClientValidation(source, clientside_arguments) {
    var capitalLetters = /.*[A-Z].*/;
    var smallLetters = /.*[a-z].*/;
    var digits = /.*[0-9].*/;
    var specialCharacters = /.*[!@~#$%^&*()].*/;
    var requiredCharacters = /[a-zA-Z0-9!\@\#\$\%\^\&\*\(\)]{8,255}/;

    var password = document.getElementById('ctl00_ContentPlaceHolder1_registerView_CreateUserWizard1_CreateUserStepContainer_Password').value;

    if (password.length < 8) 
    {
        clientside_arguments.IsValid = false;
        return;
    }
    else {
        if (password.match(requiredCharacters) == null || (password.match(requiredCharacters) != null && password.match(requiredCharacters) != password)) {
            clientside_arguments.IsValid = false;
            return;
        }
        else {
            if (password.match(capitalLetters) != null && password.match(smallLetters) != null && password.match(digits) != null) {
                clientside_arguments.IsValid = true;
                return;
            }
            else if (password.match(capitalLetters) != null && password.match(smallLetters) != null && password.match(specialCharacters) != null) {
                clientside_arguments.IsValid = true;
                return;
            }
            else if (password.match(capitalLetters) != null && password.match(digits) != null && password.match(specialCharacters) != null) {
                clientside_arguments.IsValid = true;
                return;
            }
            else if (password.match(smallLetters) != null && password.match(digits) != null && password.match(specialCharacters) != null) {
                clientside_arguments.IsValid = true;
                return;
            }
            else {
                clientside_arguments.IsValid = false;
                return;
            }
        }
    }
}
