Files
2024-07-05 21:36:15 +03:30

96 lines
3.1 KiB
JavaScript

$(document).ready(function () {
$('.wrapper label').addClass('hasValueLabel');
$('.setup-box #username').on('keyup',
function() {
checkInput(this, /^[a-zA-Z0-9@.]+$/);
inputValue();
});
$('.setup-box #password').on('keyup',
function() {
checkInput(this, /^[a-zA-Z0-9@.]+$/);
inputValue();
});
$('.setup-box #user').on('keyup',
function () {
checkInputSignUp(this, /^[a-zA-Z0-9@.]+$/);
});
$('.toggle-password').click(function () {
var passwordInput = $('#password');
var passwordFieldType = passwordInput.attr('type');
if (passwordFieldType === 'password') {
passwordInput.attr('type', 'text');
$('.toggle-password i').removeClass('fa-eye').addClass('fa-eye-slash');
} else {
passwordInput.attr('type', 'password');
$('.toggle-password i').removeClass('fa-eye-slash').addClass('fa-eye');
}
});
});
//$(window).on('pageshow', function (event) {
// if (event.originalEvent.persisted) {
// setTimeout(function () {
// inputValue();
// }, 0);
// } else {
// inputValue();
// }
//});
$('.setup-box .form-control').on('focus animationstart keyup', function () {
$(this).next().addClass("hasValueLabel");
$(this).addClass("hasValue");
});
$('.setup-box .form-control').on('blur', function () {
inputValue()
});
function inputValue(){
$('.setup-box .form-control').each(function () {
/* console.log($(this).val());*/
if ($(this).attr('type') !== 'radio' && ($(this).attr('type') !== 'checkbox')) {
if ($(this).val() !== "") {
$(this).next().addClass("hasValueLabel");
$(this).addClass("hasValue");
} else {
$(this).next().removeClass("hasValueLabel");
$(this).removeClass("hasValue");
}
}
});
}
function checkInput(element , pattern){
var regex = new RegExp(pattern);
/*console.log(regex);*/
if (!regex.test($(element).val()) && ($(element).val().length != 0)) {
$(element).addClass("errored");
$(".error-box").css("display" , "flex");
$(".error-box").text("");
$(".error-box").append("<p>لطفازبان کیبورد خود را به انگلیسی تغییر دهید.</p>");
$(element).focus();
}else{
$(element).removeClass("errored");
$(".error-box").css("display", "none");
}
}
function checkInputSignUp(element, pattern) {
var regex = new RegExp(pattern);
/* console.log(regex);*/
if (!regex.test($(element).val()) && ($(element).val().length != 0)) {
$(".addedAlarm").remove();
$(".error-box-signUp").append('<p class="addedAlarm" style="padding: 10px 7px 0px;">لطفا زبان کیبورد خود را به انگلیسی تغییر دهید.</p>');
$("#user").addClass("invalidPass");
$(element).focus();
} else {
$("#user").removeClass("invalidPass");
$(".addedAlarm").remove();
}
}