Is there a way to prevent numbers from being submitted in a text field on a Marketo form? I tried the masking feature but we need the number of characters to be flexible. Thanks in advance for your input!
Solved! Go to Solution.
Yes. The method is somewhat tricky and is not specifically mentioned in my More input mask tweaks post — which you should read anyway!
First make sure the input has a mask in Form Editor (it doesn’t matter what the mask is, but you need it to enable masks in general).
Then add a new custom mask character. We’ll use D, which will allow non-digit or empty at any position.
Then you can set the mask to 255 x D for a field with special placeholder and autoclear options. This is equivalent to allowing up to 255 non-digits:
MktoForms2.$("body").on("mkto_inputmask_polyfilled", function(e) {
MktoForms2.whenReady(function(readyForm) {
// new mask "D" = non-digit or empty
const maskCharExtensions = {
"D": /^(\D|)$/
};
Object.keys(maskCharExtensions)
.forEach(function(char) {
MktoForms2.$.mask.definitions[char] = maskCharExtensions[char];
});
});
MktoForms2.whenReady(function(readyForm){
MktoForms2.$("[name='LastName']").mask("D".repeat(255), { placeholder: "", autoclear: false });
});
});
Yes. The method is somewhat tricky and is not specifically mentioned in my More input mask tweaks post — which you should read anyway!
First make sure the input has a mask in Form Editor (it doesn’t matter what the mask is, but you need it to enable masks in general).
Then add a new custom mask character. We’ll use D, which will allow non-digit or empty at any position.
Then you can set the mask to 255 x D for a field with special placeholder and autoclear options. This is equivalent to allowing up to 255 non-digits:
MktoForms2.$("body").on("mkto_inputmask_polyfilled", function(e) {
MktoForms2.whenReady(function(readyForm) {
// new mask "D" = non-digit or empty
const maskCharExtensions = {
"D": /^(\D|)$/
};
Object.keys(maskCharExtensions)
.forEach(function(char) {
MktoForms2.$.mask.definitions[char] = maskCharExtensions[char];
});
});
MktoForms2.whenReady(function(readyForm){
MktoForms2.$("[name='LastName']").mask("D".repeat(255), { placeholder: "", autoclear: false });
});
});
Thank you, Sanford! That solution worked perfectly!