SOLVED

Re: Form-Phone Number Variations

Go to solution
Anonymous
Not applicable

For all our forms, phone number field is causing a issue in reports as users can enter just a single digit, is there is a workaround? to limit the minimum phone number digits?

1 ACCEPTED SOLUTION
SanfordWhiteman
Level 10 - Community Moderator

Is there someway to alter the code to be conditional to run only if phone number is in the form? Thanks!

Sure, you can check if the Phone number exists at all in the initial form field set. I updated the Pen accordingly.

 

View solution in original post

15 REPLIES 15
SanfordWhiteman
Level 10 - Community Moderator

See some examples of what you can do at MktoForms2 :: Extended Phone Validation

Obviously you can go down a real rabbit hole in trying to allow user-formatted entries while still trying to detect "obviously" bad formats. That's why usually phone #s are masked to a particular format, though as Josh said this has to be localized.

jdm739
Level 1

Hi Sanford, 

 

Thank you for your code - it works. But I'm running into an issue where if it's on a landing page template that hosts multiple different forms without phone number as a field, the form will not submit. Is there someway to alter the code to be conditional to run only if phone number is in the form? Thanks!

SanfordWhiteman
Level 10 - Community Moderator

Is there someway to alter the code to be conditional to run only if phone number is in the form? Thanks!

Sure, you can check if the Phone number exists at all in the initial form field set. I updated the Pen accordingly.

 

stephaniadamcik
Level 1

Perfect - thank you!

tarajosealander
Level 1

Is there a way to require the number to be real and US based? I can lock it to 10 digits, but will that ensure it is an actual us based phone number?

SanfordWhiteman
Level 10 - Community Moderator

You can't do this validation with Marketo alone. There are various remote services that can do so — for example, the Twilio Lookup API.

Hoi_Nguyen3
Level 2

Hi Sanford,

Thanks for sharing that javascript. So I copied and pasted and the error message does pop up, however, I'm still able to submit the form itself and am taken to the thank you page. 

Here is a test landing page I created:

https://go.greenhouse.io/Demo-Test.html

Can you advise on how I can ensure that the user can NOT submit the form if they input a phone number that is less than 7 digits or more than 13 digits?

Thanks,

Hoi

SanfordWhiteman
Level 10 - Community Moderator

Because you have another JS script loaded via GTM (you must keep track of those!) that's overriding the validation and setting the form back to submittable.

pastedImage_1.png

No idea what the above is supposed to do, but you need to make sure all your custom form behaviors cooperate with each other.

Josh_Hill13
Level 10 - Champion Alumni

Other than what Deval said, you can use javascript on the page to help manage this.

If you are a global company though, you will need to take into account Intl Codes and lengths.

Devraj_Grewal
Level 10 - Champion Alumni

Will, you can use the mask input feature (Apply Input Masking to a Field in a Form - Marketo Docs - Product Docs) for the phone number field on the form. Make it a text field and by inputting "9999999999" you then require the field to have a maximum of 10 numbers. I do not believe it can enforce a minimum length though.

Anonymous
Not applicable

Do you know if this supports international numbers too? thanks!

Geoff_Krajeski1
Level 10 - Champion Alumni

I have not found a way to mask like you are asking for, which is also disappointing here.

If there were the ability to mask in one of two ways either of ##-###-###-#### or ###-###-#### it would be great, and solve the international issue, however, this is not an option without customization.

SanfordWhiteman
Level 10 - Community Moderator

I'll show you how to max and min it up using a custom validator later tonight.

Devraj_Grewal
Level 10 - Champion Alumni

You can input as many "9" digits necessary, it just enforces that an inputted number cannot have more digits than what you allow.

Anonymous
Not applicable

Not in the form builder.  You will need some validation logic on your webpage to do this