Re: 電話番号の文字数制限

Anonymous
Not applicable

フォームの電話番号フィールドが入力必須なのに3ケタ入力しただけで

送信できてしまいます。

設定はフォームのフィールドの詳細で行うものですか?

11 REPLIES 11
Josh_Hill13
Level 10 - Champion Alumni

If you need 3 digits in the field, you can use field masking in the Form Setup, but it won't force it. You need javascript to enforce rules for this. Find a web developer.

Anonymous
Not applicable

HI Josh

Thank you for your help.

Other expert answered this question,but it didn't enough.

I don't need to have 3 digits, 

The probrem is that the phone field would be sent with the phone number which is incorrect,

even if the field is input required.

I found the code below and need to change the green colored part to put it in our embed code.

Would you help me?

form.vals({ "Phone":"555-555-1234", "Country":"USA"});

1. The minimum number is 10 and no hyphen. How do you code?

2. "Phone"  should be same as the field name of the form, right?

3. Is "Country" necessary? If so,what it would be like?  For example,"japan" didn't work. "ja" ? "JAPAN" ?

Casey_Grimes
Level 10

風間さん、

この例ではあなたが望むものではありません。あれはデータを事前入力するフォームのAPIを使用しています。この問題を解決するためにJavaScriptを使用しています。電話番号10文字の入力をしたい場合は、使用:

<script type="text/javascript">

document.addEventListener('DOMContentLoaded', function() {

document.getElementById("phone")[0].setAttribute("pattern", ".{10,}");

});

</script>

ちょっと日本語を話せでも〜5年で話されていません。済みません。

ーグライムズ

SanfordWhiteman
Level 10 - Community Moderator

Hey Courtney,

This should in the form's onReady, not in the body onload, otherwise you have a race condition (the form elements can't be expected to exist onload).

Casey_Grimes
Level 10

そうですねーupdated accordingly.

SanfordWhiteman
Level 10 - Community Moderator

Unless there's something I'm missing in the Japanese it still has to be in MktoForms2.whenReady.

DOMContentLoaded is guaranteed to miss the element.

Or is this not a Marketo form?

Casey_Grimes
Level 10

Is there a way to call the form once it's fully loaded without specifying the actual form via the Forms 2.0 JS API, though? I'm trying to come up with a neutral solution, and usually when deploying something neutral I've got something to go with in terms of an action beyond page fully loaded, a la:

var parentForm = document.querySelector("[id^=mktoForm_]");

parentForm.addEventListener("action", someFunction, false);

SanfordWhiteman
Level 10 - Community Moderator

When you use whenReady, you don't need to know the form ID. It fires for every form on the page, and it's guaranteed to fire when the form is in the DOM and ready for special JS tricks.

MktoForms2.whenReady(function(form){

  var formEl = form.getFormElem()[0]; // formEl is the native DOM element #mktoForm_*, unwrapped from the jQuery (ugh) object

});

The only way other than using the MktoForms2 events would be DOM Mutation Events. But I don't know why that'd be necessary.

Anonymous
Not applicable

Thank you for your reply.

I am not a js expert, how can I custmize?

The script  is below.

<script src="//app-ab00.marketo.com/js/forms2/js/forms2.min.js"></script>

<form id="mktoForm_0000"></form>

<script>MktoForms2.loadForm("//app-ab00.marketo.com", "000-MMM-000", 0000);</script>

Anonymous
Not applicable

See Forms 2.0 » Marketo Developers​ example 3 and 7

I think your code

form.vals({ "Phone":"555-555-1234", "Country":"USA"});

is not validation code.

i think Example 9 is your solution.

Anonymous
Not applicable

Hi Takahashi San

日本人の方でいらっしゃいますか?

お答えありがとうございます。