Jump to content
thirty bees forum
  • 0

white space phone number



When creating a new address, we can save it into the DB even the phone number is just a whitespace.

To test: BO > Customers > Addresses > Set required fields for this section > make the phone required, FO > Sign in > My addresses > Add a new address > fill the phone number with whitespace and "Save", check if the error message is displayed.

The following almost fixes it, it makes it so you can't just put in a space, but doesn't fix the fact when you put in a space, goto a different field, the phone # field you just put a space in colors green for good. It also doesnt take into factor that I can put in an incomplete phone number, like 123-456-7 or 1234567, in the US it should have 10 digits.(ie. 123-456-7890) I guess I could change it to 10,15 or something.... ``` public static function isPhoneNumber($number) { $phoneNumber = preg_replace("/[+. ()-]/", "", $number);

    return (bool)preg_match('/^[0-9]{7,15}$/', $phoneNumber);

``` This is a replacement for the function in /classes/Validate.php

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

Hi, May be you should to find a way to override the validate javascript function to match with this. You can find it in validate.js in root/js dir. It's just a function:

function validate_isPhoneNumber(s) { s.replace(/ +/g, "-"); var reg = /^[0-9]{7,15}$/; return reg.test(s); } I'm not really fan of regex, this one is wrong, but it should be something like that. Make the validation process before send the form, in my opinion, is better than doing it after with the validate.php.


Link to comment
Share on other sites

  • 0

Looks like I'm trying to fix this, and it's a very complicated problem to validate all phone numbers. This one seems to work fairly well... /^[+]?(1\-|1\s|1|\d{3}\-|\d{3}\s|)?((\(\d{3}\))|\d{3})(\-|\s)?(\d{3})(\-|\s)?(\d{4})$/g

I dont know what the final answer is, I just dont want people to be able to just put in a whitespace for their phone number

Link to comment
Share on other sites

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...