Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save felipeabajo/d91fb8897ccfece7e15e076e6948e24c to your computer and use it in GitHub Desktop.
Save felipeabajo/d91fb8897ccfece7e15e076e6948e24c to your computer and use it in GitHub Desktop.
JS for checking special characters in a field of a form in a model driven Power App
function CheckForSpecialCharacters(executionContext) {
'use strict';
var formContext = executionContext.getFormContext();
var StreetAddressField = formContext.getAttribute("crf8e_nombre").getValue();
const specialChars = /[`!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?~]/;
if (StreetAddressField === null) return;
if (specialChars.test(StreetAddressField)) {
formContext.getControl("crf8e_nombre").setNotification("The following characters are not allowed: [`!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?~]", 102);
return false;
} else {
formContext.getControl("crf8e_nombre").clearNotification(102);
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment