Jump to content

9 digits phone validation


c64girl

Recommended Posts

How to make 9 digits validation no more nor less but 9 numbers only?

 

I Found this:

/js/validate.js

function validate_isPhoneNumber(s)
{
    var reg = /^[+0-9. ()-]+$/;
    return reg.test(s);
}

/classes/Validate.php

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

 

Link to comment
Share on other sites

On 8/10/2023 at 6:54 PM, c64girl said:

How to make 9 digits validation no more nor less but 9 numbers only?

 

Hi,

Try this:

In /js/validate.js file,

function validate_isPhoneNumber(s)
{
    var reg = /^[0-9]{9}$/;
    return reg.test(s);
}

In /classes/Validate.php

public static function isPhoneNumber($number)
{
    return preg_match('/^[0-9]{9}$/', $number);
}

Once you made the above changes, Clear the cache and check If it works!

Thanks!

Link to comment
Share on other sites

On 8/14/2023 at 8:26 AM, AddWeb Solution said:

Hi,

Try this:

In /js/validate.js file,

function validate_isPhoneNumber(s)
{
    var reg = /^[0-9]{9}$/;
    return reg.test(s);
}

In /classes/Validate.php

public static function isPhoneNumber($number)
{
    return preg_match('/^[0-9]{9}$/', $number);
}

Once you made the above changes, Clear the cache and check If it works!

Thanks!

 

 

Thank You for idea but it still not working after making changes and clear cache.

 

 

 

obraz.png.79b13d4744afb9d4312c7a30e59ad0b5.png

Edited by c64girl (see edit history)
Link to comment
Share on other sites

On 8/14/2023 at 8:26 AM, AddWeb Solution said:

Hi,

Try this:

In /js/validate.js file,

function validate_isPhoneNumber(s)
{
    var reg = /^[0-9]{9}$/;
    return reg.test(s);
}

In /classes/Validate.php

public static function isPhoneNumber($number)
{
    return preg_match('/^[0-9]{9}$/', $number);
}

Once you made the above changes, Clear the cache and check If it works!

Thanks!

I know what is the problem. If someone have allready put it a number with + or - or space or more or less than 9 digits it brake the PS for him in checkout.

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