SOLVED

Form Validation - do not allow numbers

Go to solution
Highlighted
Level 6 - Champion Alumni

Form Validation - do not allow numbers

Does anyone have a sample form validation script that will not allow numbers to be entered in the first or last name field?

Thanks,

Jason

Tags (3)
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Level 10 - Community Moderator

Re: Form Validation - do not allow numbers

Unfortunately, the example code has a bug (always has). It doesn't correctly check against built-in validation, which can end up being very confusing when writing custom validators.

Something more extensible: MktoForms2 :: Extended Validation from Validators Array

View solution in original post

4 REPLIES 4
Highlighted
Anonymous
Not applicable

Re: Form Validation - do not allow numbers

Hi Jason Hamilton

<script>

MktoForms2.loadForm("//app-ab99.marketo.com", "999-IBN-999", 9999, function (form) {

    //listen for the validate event

    form.onValidate(function() {

        // Get the values

        var vals = form.vals();

        //Check your condition

        if (vals.FirstName.match(/[0-9]+/) || vals.LastName.match(/[0-9]+/)) {

            // Prevent form submission

            form.submittable(false);

            // Show error message, pointed at VehicleSize element

            form.showErrorMessage("I don't like numbers!");

        }

        else {

            // Enable submission for those who met the criteria

            form.submittable(true);

        }

  });

});

</script>

http://developers.marketo.com/documentation/websites/forms-2-0/

This code is based on example 9

Highlighted
Level 10 - Community Moderator

Re: Form Validation - do not allow numbers

Unfortunately, the example code has a bug (always has). It doesn't correctly check against built-in validation, which can end up being very confusing when writing custom validators.

Something more extensible: MktoForms2 :: Extended Validation from Validators Array

View solution in original post

Highlighted
Level 6 - Champion Alumni

Re: Form Validation - do not allow numbers

Worked great as usual, thanks Sanford Whiteman

Highlighted
Level 6 - Champion Alumni

Re: Form Validation - do not allow numbers

I have another question re integrating corporate email validation into this, but I will start a new string.