Jump to content
thirty bees forum
  • 0

Phone number validation - problem for some customers


Question

Posted

A customer wrote today saying they couldn't order because their phone number was being rejected as invalid.

I followed the instruction here https://www.prestashop.com/forums/topic/393876-how-disable-phone-number-format-check/

and did this:

Find in classes/Validate.php

public static function isPhoneNumber($number) { return preg_match('/^[+0-9. ()-]*$/', $number); } and change to:

public static function isPhoneNumber($number) { return true; } I'm wondering what the customer might have entered that gave the error. Do I read the original code properly that it demands a plus? If so, it might be a good idea to change that. I'm sure this affects lots of customers.

12 answers to this question

Recommended Posts

  • 0
Posted

For debugging you can change this validation method to this:

```php public static function isPhoneNumber($number) { if (!pregmatch('/^[+0-9. ()-]*$/', $number)) { fileputcontents(PSROOTDIR.'/config/phonenumbers-failed', varexport($number, true)."\n", FILE_APPEND); }

return true;

} ``` This will create a file config/phonenumbers-failed and list all the failed phone numbers inside there. Still report success in any case.

  • 0
Posted

My guess would be that for some reason she cut & paste her phone number into the field and inadvertently included a trailing CR, LF, tab, etc. Alternatively if she c&p from Word it could have had the dashes replaced with special characters.

Another problem that happens with customers from some countries is they end up using double width numbers instead of half width (aka normal) numbers.

  • 0
Posted

@traumflug said in Phone number validation - problem for some customers:

inadvertently included a trailing CR, LF, tab,

tripping over such a situation would be a bug.

After a little testing it will fail if a tab is included but CR LF seem to be replaced with a space. Using an em dash will also cause validation to fail.

My expectation would be that any special character, visible or not (besides CR LF), will cause phone number validation to fail.

  • 0
Posted

Unless the phone number field is to be used for auto-sending SMS or something like that then is validation really needed at all?

Removing validation would allow customers to include extension numbers (common for offices) or other bits of info that might occur in some phone numbers.

  • 0
Posted

As @mdekker mentioned in the Github issue, such phone numbers potentially get sent to many places, like carriers, payment processors or similar. Shaping the number would avoid it becoming stuck later.

With 'shaping' I mean things like replacing all the various whitespace types with an ordinary space character, replacing various dash types with the ordinary minus sign and such stuff.

  • 0
Posted

Such shaping is going to be difficult with the nearly endless number of unicode characters. Japanese alone has 7 or 8 different dash type characters, and that's not including the funky ones that are dash-like but not actually dashes. I expect other complex languages will have similar numbers to deal with. There are also 9 or 10 different possible bracket styles in Japanese. Crazy, yes.

It's probably best to give people a list of valid characters they can use and then either refuse to accept input with invalid characters (like now) or brute-force strip invalid characters with Regex.

  • 0
Posted (edited)

I was using regex to verify the input of phone number and here's the code:

^([+])?([^\\d]?\\d){5,18}$

 But I found it so limited because I wanted to check if the number exists or not.

For that, I did some research and finally, I started using Veriphone

Edited by Ayoub
  • 0
Posted
2 hours ago, Ayoub said:

For that, I did some research and finally, I started using Veriphone

This would remove customers like me from your shop. I never give a valid phone number. "The Internet" can't abuse things it doesn't know.

  • Like 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...