Skip to main content

Change validation rules

Changes the validation rules of the number and email fields in the document.

(function () {
let doc = Api.GetDocument();
let forms = doc.GetAllForms();

forms.forEach((form) => {
if (form.GetFormType() === "textForm") {
let formKey = form.GetFormKey();
let formText = form.GetText();

if (/^\(\d{3}\)\d{3}-\d{4}$/.test(formText)) {
form.SetCharactersLimit(14);
form.SetRequired(true);
form.SetPlaceholderText("(123)456-7890");
form.SetComb(true);
} else if (
/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(formText)
) {
form.SetCharactersLimit(254);
form.SetRequired(true);
form.SetPlaceholderText("example@example.com");
}
}
});
})();

Methods used: GetDocument, GetAllForms, GetFormType, GetFormKey, GetText, SetCharactersLimit, SetRequired, SetPlaceholderText, SetComb

Result

ChangeValidationRules ChangeValidationRules