"}
};
function isValidDate(dateString)
{
// First check for the pattern
if(!/^\d{1,2}\/\d{1,2}\/\d{4}$/.test(dateString))
return false;
// Parse the date parts to integers
var parts = dateString.split("/");
var day = parseInt(parts[1], 10);
var month = parseInt(parts[0], 10);
var year = parseInt(parts[2], 10);
// Check the ranges of month and year
if(year < 1000 || year > 3000 || month == 0 || month > 12)
return false;
var monthLength = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ];
// Adjust for leap years
if(year % 400 == 0 || (year % 100 != 0 && year % 4 == 0))
monthLength[1] = 29;
// Check the range of the day
return day > 0 && day <= monthLength[month - 1];
};
$.ajax({
async: true,
type: "POST",
url: "/Account/Register?returnUrl=" + encodeURIComponent(''),
contentType: "application/json",
data: JSON.stringify(data),
success: function (x) {
//GA tracking specifically for Purewin brand
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
'event':'nrc',
'user.uid': data.email, // unique user ID, that is the same when user returns - Had to be done email as at this point we don't return a unique id
'reg.success':'yes', // no on fail, yes on registration succeeded.
});
reloadGame();
$("#register-dialog").show();
$(".loading-dialog").hide();
},
error: function (x) {
if(x && x.responseJSON){
// Clear previous validation messages in the register dialog only
var fields = ["Nickname-validation", "Name-validation", "Surname-validation", "DateOfBirth-validation", "Email-validation", "PhoneNumber-validation", "Password-validation"];
for(var fieldId of fields){
var span = $("#partial-register #"+fieldId);
span.removeClass("field-validation-error");
span.html("");
}
for(var key in x.responseJSON){
var errors = x.responseJSON[key];
for(var error of errors){
var spanSelector = key + "-validation";
var span = $("#partial-register #" + spanSelector);
if(span.length > 0){
span.addClass("field-validation-error");
span.html(error);
}
}
}
}
//GA tracking specifically for Purewin brand
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
'event':'nrc',
'user.uid': data.email, // unique user ID, that is the same when user returns - Had to be done email as at this point we don't return a unique id
'reg.success':'no', // no on fail, yes on registration succeeded.
});
$("#register-dialog").show();
$(".loading-dialog").hide();
}
});
});