Post by t_mask17 » Mon Mar 14, 2011 4:01 pm

I've check and test the opencart system I notice that it doesnt validate numbers...Also any idea on how I could separate
Telephone number in 3 parts

like 1st text box "Country Code"
2nd textbox "Area Code"
3rd "Telephone Number"

also Where Could I find the REGEX of the telephone so it would accept numbers only...

Thanks

Newbie

Posts

Joined
Mon Mar 14, 2011 2:33 pm

Post by justinv » Thu Mar 17, 2011 6:16 am

In the associated controller there will be a function called validate(). You can check in this function whether the telephone number preg_match("\d+") or the regex you require and return error if not. Then you will have your telephone validation.

Documentation: OpenCart User Guide
Mods: Total Import PRO | CSV Import PRO | Ecom Tracking | Any Feed | Autosuggest | OpenCart CDN
Image


Active Member

Posts

Joined
Tue Oct 12, 2010 1:24 pm

Post by tim21701 » Sun Mar 20, 2011 4:02 am

how to do this? Show me an example. Please.

User avatar
Newbie

Posts

Joined
Fri Feb 25, 2011 5:46 pm
Location - Russia, Murmansk

Post by justinv » Sun Mar 20, 2011 7:35 am

For example, the account creation page: catalog/controller/account/create.php

You will see in that file a line that says this:

Code: Select all

if ((strlen(utf8_decode($this->request->post['telephone'])) < 3) || (strlen(utf8_decode($this->request->post['telephone'])) > 32)) {
      		$this->error['telephone'] = $this->language->get('error_telephone');
    	}
That is checking that the telephone given is between 3 and 32 characters long. You could make it also check that it was only digits like this:

Code: Select all

if ((strlen(utf8_decode($this->request->post['telephone'])) < 3) || (strlen(utf8_decode($this->request->post['telephone'])) > 32) || preg_match('/[^\d]/is', $this->request->post['telephone'])) {
      		$this->error['telephone'] = $this->language->get('error_telephone');
    	}
You can do this same in the controllers on any other pages - eg the checkout pages.

Documentation: OpenCart User Guide
Mods: Total Import PRO | CSV Import PRO | Ecom Tracking | Any Feed | Autosuggest | OpenCart CDN
Image


Active Member

Posts

Joined
Tue Oct 12, 2010 1:24 pm

Post by mberlant » Wed Mar 23, 2011 10:32 pm

It is very difficult and often counterproductive to effectively validate a telephone number.

Country Codes, City Codes and telephone numbers vary in length country to country, and often also within a country. Country Codes can be 1, 2 or 3 digits long and the entire telephone number, including the Country Code, may be not more than 15 digits long.

Also, be careful about limiting the entry in the telephone number field to digits only. You will deprive someone behind a switchboard of the ability to enter an extension number, which may prevent that customer from receiving your shipment.

t_mask17, what problem are you trying to solve or correct by asking for this advice?

Please use proper English at all times, so that all members may understand you.


User avatar
Active Member

Posts

Joined
Sun Mar 13, 2011 8:33 pm
Who is online

Users browsing this forum: No registered users and 10 guests