You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.2 KiB

const validation = new JustValidate("#signup");
validation
.addField("#name", [
{
rule: "required"
}
])
.addField("#email", [
{
rule: "required"
},
{
rule: "email"
},
{
validator: (value) => () => {
return fetch("validate-email.php?email=" + encodeURIComponent(value))
.then(function(response) {
return response.json();
})
.then(function(json) {
return json.available;
});
},
errorMessage: "email already taken"
}
])
.addField("#password", [
{
rule: "required"
},
{
rule: "password"
}
])
.addField("#password_confirmation", [
{
validator: (value, fields) => {
return value === fields["#password"].elem.value;
},
errorMessage: "Passwords should match"
}
])
.onSuccess((event) => {
document.getElementById("signup").submit();
});