Jump to content
nabuchodonozor

Phone Number Validation

Recommended Posts

Hello guys, I need to do validation in phone number. I need 9 digits validation in my form. Im using presta 1.6. Please help me guys <3

Share this post


Link to post
Share on other sites

Change the Validate::isPhoneNumber method. Now, these characters are permitted (any number): 0-9. ()-

  • Like 1

Share this post


Link to post
Share on other sites
    public static function isPhoneNumber(9)
    {
        return preg_match('/^[0-9]{0,9}$/', $number);
    }

 

 

Is that correct now?

I want to do something, that will be requiering to type 9 digits, because now somebody, can write only 1 digit in form...

Edited by nabuchodonozor (see edit history)

Share this post


Link to post
Share on other sites

replace like this.

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

Share this post


Link to post
Share on other sites

I will try it ASAP. Which filles have I to delete too?

you don't need any delete file .

open this file

classes/validate.php

and replace this function

public static function isPhoneNumber($number)

Share this post


Link to post
Share on other sites

Yes i know. I did this now. But there is no changes, I can still write 1 digit, maybe it have to took some time until form will update?

Share this post


Link to post
Share on other sites

i tested and it worked for me .

you have any override files ?

or maybe your current theme will use special validate function

Share this post


Link to post
Share on other sites

Im using default theme. I tried to override validate.php file but I didnt knew how to did it. So i think that there is no files after override. Can you upload your validate.php ?

Share this post


Link to post
Share on other sites

file is athacded ,

upload this file to

/override/classes folder

after delete this file

/cache / class_index.php

 

 

Validate.php

Edited by safa (see edit history)

Share this post


Link to post
Share on other sites

Now its working! Thanks Bro. I have one more question. How can I now edit the message which is informing customer about this form. I mean that i want to do something that will show another error message than the default one. " Please enter full phone number 111-222-333" Or something like that.

Share this post


Link to post
Share on other sites

 

replace like this.

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

 

This is not 100% corrert solution.

This code will only check, if there are 9 characters, but not check if all characters are digits.

 

Correct code is 

    public static function isPhoneNumber($number)
    {
        return (preg_match('/^[+0-9. ()-]*$/', $number) AND strlen($number) == 9);
    }
Edited by Petr Pánek (see edit history)
  • Like 1

Share this post


Link to post
Share on other sites

If you want do also inline validation in the form, change the validate.js function validate_isPhoneNumber(s) this way:

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

Share this post


Link to post
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...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More