Jump to content

Registration form - phone validation


Recommended Posts

Is there a way to validate the phone number?

i.e. i need it to be 10 digits exactly

If you told us your PS version that would help. Without it, I am guessing.

 

Drop the attached file to /override/classes/ directory on your server, it is good for 1.4.7.0.

 

But consider that most people will type brackets, hyphens, spaces etc when typing their phone numbers and maybe surprised why it is not being accepted. Better to have a few wrong phone numbers than puzzling most of your users IMO.

Link to comment
Share on other sites

  • 1 month later...

Hi agiropoulostauros,

 

I have just solved the problem of validating the phone number on the contact form. Not sure if the account registration form is same as that form that you mentioned. Nevertheless, I hope the following solution helps you and everyone else. :)

 

1) Go to AuthController.php in controllers folder.

2) Go to Line 85 and find

 

if (!Tools::getValue('phone') AND !Tools::getValue('phone_mobile'))

$this->errors[] = Tools::displayError('You must register at least one phone number');

 

3) Copy and paste the following after line 85:

 

(this is for validating the mobile phone number)

$digits_mobile = strlen(Tools::getValue('phone_mobile'));

if (Tools::getValue('phone_mobile') AND $digits_mobile !=10)

$this->errors[] = Tools::displayError('Please enter 8 digits for the mobile phone number.');

(this is for validating the home phone number)

$digits_home = strlen(Tools::getValue('phone'));

if (Tools::getValue('phone') AND $digits_home !=10)

$this->errors[] = Tools::displayError('Please enter 8 digits for the home phone number.');

 

4) Refresh the form page, and see if it works for you.

 

P.S Please back up the file before you can actually do the above actions.

 

 

Cheers,

Andre

  • Like 3
Link to comment
Share on other sites

  • 7 months later...
  • 4 weeks later...
  • 6 months later...

Sorry guys, it has been a long while since I used Prestashop and I didn't check my emails related to Prestashop.

 

Just to answer your question, ricky11.... I think that version was 1.4... Hope you managed to solve your problem by then.

 

Ajax30 & tsuval, it's my pleasure and I'm really glad that it works on your side. :)

 

Ajax30, I think my code was designed for version 1.4... Surprised it works on 1.5.2..

 

All the best with your web coding works on Prestashop websites!

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

  • 10 months later...
  • 10 months later...
  • 10 months later...

Hi agiropoulostauros,

 

I have just solved the problem of validating the phone number on the contact form. Not sure if the account registration form is same as that form that you mentioned. Nevertheless, I hope the following solution helps you and everyone else. smile.png

 

1) Go to AuthController.php in controllers folder.

2) Go to Line 85 and find

 

if (!Tools::getValue('phone') AND !Tools::getValue('phone_mobile'))

$this->errors[] = Tools::displayError('You must register at least one phone number');

 

3) Copy and paste the following after line 85:

 

(this is for validating the mobile phone number)

$digits_mobile = strlen(Tools::getValue('phone_mobile'));

if (Tools::getValue('phone_mobile') AND $digits_mobile !=10)

$this->errors[] = Tools::displayError('Please enter 8 digits for the mobile phone number.');

 

(this is for validating the home phone number)

$digits_home = strlen(Tools::getValue('phone'));

if (Tools::getValue('phone') AND $digits_home !=10)

$this->errors[] = Tools::displayError('Please enter 8 digits for the home phone number.');

 

4) Refresh the form page, and see if it works for you.

 

P.S Please back up the file before you can actually do the above actions.

 

 

Cheers,

Andre

Where does this difference come from:

"enter 8 digits" vs " $digits_mobile !=10"?

 

Thank you!

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