57 lines
2.1 KiB
JavaScript
57 lines
2.1 KiB
JavaScript
passwordPatern = /^[a-zA-Z0-9]{8,16}$/;
|
|
loginPatern = /^[a-z]{8,16}$/
|
|
mailPatern = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; //https://emailregex.com/
|
|
datePatern = /^\d{4}[\/\-](?:\d{1}|1[012]|0\d)[\/\-](?:\d{1}|[123]\d|0\d)/
|
|
|
|
|
|
$(function() {
|
|
$('form').on('submit',function(e) {
|
|
e.preventDefault();
|
|
var data = $(this).serialize();
|
|
var loginName = $("input[name$='login']", $(this)).val()
|
|
var url = $(this).attr('action')
|
|
if(url == "./post.php")
|
|
if (mailPatern.test($(".email input").val()) && passwordPatern.test($(".pw input").val()) && $(".pw2 input").val() == $(".pw input").val() && loginPatern.test($(".login input").val()))
|
|
{
|
|
|
|
}
|
|
else {
|
|
swal("Oops", "Something wrong in the form ", "error");
|
|
return false;
|
|
}
|
|
$.ajax({
|
|
type: 'post',
|
|
url: url,
|
|
data: data,
|
|
dataType: "json",
|
|
success: function(data) {
|
|
console.log(data);
|
|
if (typeof(data.register) != "undefined" && data.register !== null) {
|
|
if (data.register) {
|
|
swal("Good job!", "You are registered !", "success");
|
|
$('form').animate({
|
|
height: "toggle",
|
|
opacity: "toggle"
|
|
}, "slow");
|
|
} else {
|
|
swal("Oops", "Something wrong in the form : " + data.return, "error");
|
|
}
|
|
|
|
} else if (typeof(data.login) != "undefined" && data.login !== null) {
|
|
if(data.login)
|
|
{
|
|
swal("Good job!", "Welkome "+loginName+"\nYou are logged !\nYou're redirect in 5 seconds", "success");
|
|
var delay = 5000;
|
|
setTimeout(function(){ window.location = "/bil/"; }, delay);
|
|
}
|
|
else
|
|
swal("Oops", "Something wrong in the form", "error");
|
|
}
|
|
}
|
|
});
|
|
// send xhr request
|
|
|
|
});
|
|
|
|
});
|