Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

Validate US/CA Phone Number Format

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #1  
Old 11-02-2007, 06:41 PM
 
exsecror exsecror is offline
 

X-Wizard
  
Join Date: Apr 2007
Posts: 1,284
 

Default Validate US/CA Phone Number Format

The one problem I noticed rather quickly with X-Cart when it came to the required fields for the customer information input form (checking out / account registration) is that when it checks certain fields, like the phone number, it only checks the length. Now this is a big problem especially for us when we deal with Canadian orders because we have to verify certain things over the phone.

Normally this isn't an issue if the customer uses PayPal Pro Express Checkout as the payment method since they require a phone number but if they use our other payment method they get around the phone number by putting in some arbitrary character. To solve this I made a modification I wish to share with anyone wishing to do this.

This modification adds an extra check in the script check_required_fields_js.js and is easy to make. Open skin1/required_fields_js.js and on line 40 (assuming you have not modified this already), add the following:

Code:
if (document.getElementById('phone')) { if (document.getElementById('phone').value.search(/\d{3}\-\d{3}\-\d{4}/) == -1) { alert('Phone number must be in XXX-XXX-XXXX format and contain numbers!'); document.getElementById('phone').focus(); return false; } }

If you have modified the file this conditional block must go after:

Code:
... if (!obj.disabled && obj.type != 'hidden') { checkRequiredShow(obj); obj.focus(); checkRequiredShow(obj); obj.focus(); } return false; }

This will work with any input field that has the ID of phone and will force the customer to provide a phone number (unless they've disabled javascript, which requires server-side intervention which I will include later on in this post).
Reply With Quote
  #2  
Old 11-05-2007, 07:43 PM
  imexhouse's Avatar 
imexhouse imexhouse is offline
 

eXpert
  
Join Date: May 2006
Location: Canada
Posts: 377
 

Default Re: Validate US/CA Phone Number Format

What version is the for? In 4.1.x, I think it's skin1/check_required_fields_js.js not skin1/required_fields_js.js
__________________
Jack@AquasanaCA
X-CART GOLD 4.0.19 Live
DSEFU, AOM, ezCheckout, ezUpsell, ezRecommends, RememberMe, RememberAnonCarts
AquasanaCanada.com - Aquasana╝ - #1 Rated Water Filters in America!
X-CART GOLD 4.4.5 Live
CDSEO Pro v. 1.8.4
AquasanaMontreal.com
Aquasana╝ & Rhino Water Filtration Systems
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 12:32 AM.

   

 
X-Cart forums © 2001-2020