Hello,
I didn't understand how to use REGEX validation on fields like email, phone, url, vat etc ...
The code I use is the following
"email": {
validators: {
notEmpty: {
message: "e-mail richiesta!"
},
regexp: {
regexp: /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/,
message: "Indirizzo e-mail non valido."
}
}
},
FYI, my complete function is:
"use strict";
var mscRegister = function () {
var form;
var submitButton;
var validation;
var initValidation = function () {
validation = FormValidation.formValidation(
form, {
fields: {
"user_url": {
validators: {
notEmpty: {
message: "Dominio/URL richiesto!"
}
}
},
"user_login": {
validators: {
notEmpty: {
message: "Username richiesto!"
}
}
},
"first_name": {
validators: {
notEmpty: {
message: "Nome richiesto!"
},
regexp: {
regexp: /^[a-z\s]+$/,
message: "The full name can consist of alphabetical characters and spaces only",
},
}
},
"last_name": {
validators: {
notEmpty: {
message: "Cognome richiesto!"
}
}
},
"email": {
validators: {
notEmpty: {
message: "Indirizzo e-mail richiesto!"
},
emailAddress: {
message: "The value is not a valid email address"
}
}
},
"user_pass": {
validators: {
notEmpty: {
message: "Password richiesta!"
}
}
}
},
plugins: {
trigger: new FormValidation.plugins.Trigger(),
defaultSubmit: new FormValidation.plugins.DefaultSubmit(),
submitButton: new FormValidation.plugins.SubmitButton(),
bootstrap: new FormValidation.plugins.Bootstrap5({
rowSelector: ".fv-row",
eleInvalidClass: "is-invalid",
eleValidClass: "is-valid"
}),
icon: new FormValidation.plugins.Icon({
valid: "fa-light fa-circle-check",
invalid: "fa-light fa-circle-exclamation",
validating: ""
}),
}
}
);
}
var handleForm = function () {
submitButton.addEventListener("click", function (e) {
e.preventDefault();
validation.validate().then(function (status) {
if (status == "Valid") {
submitButton.setAttribute("data-kt-indicator", "on");
submitButton.disabled = true;
setTimeout(function () {
submitButton.removeAttribute("data-kt-indicator");
submitButton.disabled = false;
}, 500);
}
});
});
}
return {
init: function () {
form = document.getElementById("register_authentiform");
if (!form) {
return;
}
submitButton = form.querySelector("#register_authentiform_submit-register");
initValidation();
}
}
}();
KTUtil.onDOMContentLoaded(function () {
mscRegister.init();
});
Already looked and found nothing.
Also, the function I use is from Metronic and not the plugin, cmq really many thanks for the premium support.
Hi,
You can use any regex rule within the validation by following to the plugin documentation. Please make sure the regex rule is valid then it will work as expected.
Regards.