The code below was an attempt to remove a one at the beginning if present at all. Which should get the job done but I don't know if there are countries out there that need to start in the one.
The best result would be choosing Canada and then having a 1 as the first number when leaving the input field will cause the 1 to be deleted and a message displaying to the side why the one was removed so customers don't get confused.
Also as an added bonus if they choose Canada in the select field then the input field for state/province will turn into a select only listing Canadian Provinces. But the other is more important as it causes problems when fedex doesn't get the customers full phone number.
I
Expand|Select|Wrap|Line Numbers
- function Left(str, n){
- if (n <= 0)
- return "";
- else if (n > String(str).length)
- return str;
- else
- return String(str).substring(0,n);
- }
- function Right(str, n){
- if (n <= 0)
- return "";
- else if (n > String(str).length)
- return str;
- else {
- var iLen = String(str).length;
- return String(str).substring(iLen, iLen - n);
- }
- }
- function canadaValidate(){
- if (left(caPhone, 1) = 1)
- caPhone = right(caPhone, 10);
- document.main.SHIPPHONE = caPhone;
- }
- truncated form country select ->
- <select name=''country>
- <option value='' SELECTED> SELECT </option>
- <option value='CA'>Canada</option>
- form input for phone number ->
- <input NAME="phone" VALUE="" size="30" maxlength="30" onblur="canadaValidate(phone);">