Hi,
I've searched the community threads but cannot find the answer. We need to require 9 digits in a form field to ensure customers enter their account number correctly. Most account numbers begin with a 0. I'm able to set the Max Value to 999999999 but when I try to set the Min Value to 000000001 or variations of that, Marketo defaults back to just 0. So if a customer enters 8 or less digits, they will be able to submit the form which we do not want to happen.
Any ideas would be appreciated!
Solved! Go to Solution.
@Jo_Pitts1, I think you forgot about Input Masks.
@Anna_Blanchet1 you should be using a String field, not Number (this is an alphanumeric string you’re dealing with, not an integer) and a mask:
this is a slightly heavy weight approach to your problem, and may need some debugging.
I've cut it down from a solution designed to validate phone numbers across a range of lengths, and allows for multiple error messages and validation checks. I've gutted it down to one test (length) and one message (the length error message).
Put this on code on the page with your form
<script>
MktoForms2.whenReady(function(form) {
form.onValidate(function(nativeValid) {
if (!nativeValid) return;
var fieldName = 'accountNumber',
currentValue = form.getValues()[fieldName],
elJq = form.getFormElem().find('#' + fieldName),
limits = {
minDigits: 9,
maxDigits: 9
},
messages = {
INVALID_ACCOUNT_LENGTH: 'Please enter exactly 9 digits'
};
form.submittable(false);
if (currentValue.match(/\d/g).length < limits.minDigits ||
currentValue.match(/\d/g).length > limits.maxDigits) {
form.showErrorMessage(messages.INVALID_ACCOUNT_LENGTH, elJq);
return false;
}
form.submittable(true);
});
});
</script>
Cheers
Jo
@Jo_Pitts1, I think you forgot about Input Masks.
@Anna_Blanchet1 you should be using a String field, not Number (this is an alphanumeric string you’re dealing with, not an integer) and a mask:
Thank you Sanford!