phone number field in customer address

Amit_Kumar5
Tourist
31 0 3

Hi,

The phone number field in the customer address should be of 10 digits, if it is less than or more than 10 digits then it should return the error as incorrect phone number.

Please suggest how to achieve this.

www.limpkin.in

Regards,

Abhishek

Robert_P_
Shopify Staff (Retired)
Shopify Staff (Retired)
37 0 2

Hello Abhishek!

My name is Rob, and I am one of the Shopify Gurus.

The reason we allow for phone numbers less, and more than, 10 digits is because of the large varieties of phone numbers around the world. There can be between 4-13 characters, as each country has it's own system. Many countries do fall into the 10 character limit, but this varies for countries like China and Austria. 

As to changing that, the checkout is locked, for reasons of security. While changes can be made for merchant on the Plus level plans, there would be no other way to make alterations to the checkout. Besides, it could have the potential of losing sales to other nations. Great question though, and I hope you have an excellent day!

Warm regards, 

Robert P

Shopify Guru

0 Likes
Amit_Kumar5
Tourist
31 0 3

Thank you for your reply Robert. I am indeed loosing customers of my own country due to missing digits of phone number provided while booking any order as the courier guys are unable to reach them.

I also understand there might be security related issues but at the same you are giving this feature to Plus level plans. I hope Shopify understands customers across countries and roll outs few important features for us where the chances of mistakes by end user is minimal.

Thank you again and have a nice week ahead.

Regards,

Abhishek

https://www.limpkin.in/

0 Likes
KevinFilteau
Shopify Partner
5 1 5

Why not juste change the phone number validation according to selected country? #FeatureRequest.

0 Likes
KevinFilteau
Shopify Partner
5 1 5

I wrote this before I actually tested it. The phone number is validating according to the selected country. A client of mine said they sometime had incomplete phone numbers, but the country is ok (canada). It's seems to be in very specific cases. But I don't have much information about the browser / os / antispam etc.

0 Likes
MM74
New Member
1 0 0

Hello,

I have a problem with phone nubmer format, in morocco mobile phone could have many format 06xxxxxxxx or 07xxxxxxxx. And customer can use business phone number that start with 05xxxxxxxx.

 

But only those starting with 06 are allowed.

Regards

 

0 Likes
Kumar2573
Explorer
75 4 8

<script>

(function($) {

window.PhoneNumberInputFormatter=function(){return false;};

$(document).on('page:load page:change', function() {

if (Shopify.Checkout.step === 'contact_information') {

var $phoneField = $('[name="checkout[shipping_address][phone]"]:not([tabindex="-1"])'),

phoneFormatValidated = false;

// Remove automatic formatting triggers

$phoneField.removeAttr('data-phone-formatter data-phone-formatter-country-select');

// Set maxium size

$phoneField.attr('maxlength', 20);

function phoneNumberValidation() {

phoneFormatValidated = false;

 

var phoneFieldVal = $phoneField.val();

 

// Strip out any non-numeric characters

var formattedPhoneValue = phoneFieldVal.replace(/[^0-9]/g, '');

$phoneField.val(formattedPhoneValue);

phoneFormatValidated = true;

}

// Run validator if there is a previously cached phone number

if ($phoneField.val() != "") { phoneNumberValidation() };

// Run validator when the user has switched focus from the phone field

$phoneField.on('blur', phoneNumberValidation);

// Run the function when the continue button is clicked or the enter key is pressed

$('[data-step] form [type="submit"]').on('click', function(e) {

e.preventDefault();

phoneNumberValidation();

if (phoneFormatValidated) {

$('[data-step] form').trigger('submit');

}

});

 

$('[data-step] form').on('keypress', function(e) {

if (e.keyCode === 13) {

e.preventDefault();

$('[data-step] form [type="submit"]').trigger('click');

}

});

}

});

})(Checkout.$);

</script>

0 Likes
Kumar2573
Explorer
75 4 8

<script>

(function($) {

window.PhoneNumberInputFormatter=function(){return false;};

$(document).on('page:load page:change', function() {

if (Shopify.Checkout.step === 'contact_information') {

var $phoneField = $('[name="checkout[shipping_address][phone]"]:not([tabindex="-1"])'),

phoneFormatValidated = false;

// Remove automatic formatting triggers

$phoneField.removeAttr('data-phone-formatter data-phone-formatter-country-select');

// Set maxium size

$phoneField.attr('maxlength', 20);

function phoneNumberValidation() {

phoneFormatValidated = false;

 

var phoneFieldVal = $phoneField.val();

 

// Strip out any non-numeric characters

var formattedPhoneValue = phoneFieldVal.replace(/[^0-9]/g, '');

$phoneField.val(formattedPhoneValue);

phoneFormatValidated = true;

}

// Run validator if there is a previously cached phone number

if ($phoneField.val() != "") { phoneNumberValidation() };

// Run validator when the user has switched focus from the phone field

$phoneField.on('blur', phoneNumberValidation);

// Run the function when the continue button is clicked or the enter key is pressed

$('[data-step] form [type="submit"]').on('click', function(e) {

e.preventDefault();

phoneNumberValidation();

if (phoneFormatValidated) {

$('[data-step] form').trigger('submit');

}

});

 

$('[data-step] form').on('keypress', function(e) {

if (e.keyCode === 13) {

e.preventDefault();

$('[data-step] form [type="submit"]').trigger('click');

}

});

}

});

})(Checkout.$);

</script>

0 Likes
cyberscape
New Member
1 0 0

Hello Kumar2573, thank you for valuable input, I just needed to ask whether this will work to limit the phone number digits to 10, neither less than nor more than 10? and where do I have to put that code? I'm sorry if I come across as rather ignorant as I'm extremely amateur in these technical things. pardon.
I'll be extremely grateful for your help.

Thanks

0 Likes