Mandatory 10 digit phone number for certain fields
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2018 07:32 AM
I have a need for a client script for a catalog item that will not allow you to submit unless the phone number is 10 digits, however on the form I created there is a choice list that has 3 choices, change existing efax account, request new efax number and port existing number. Each of these when selected shows different variables. The script I used worked fine for other catalog items but this one has the choice list and if you have 1 selected, the fields for the other 2 are hidden and the script is still requiring it. My question is, how would I add to the script I have here to say has to be 10 digits and change existing efax account is selected. I put 3 client scripts for each choice as of now, is there a better way to achieve this?
function onSubmit() {
//Type appropriate comment here, and begin script below
var phone = g_form.getValue('current_number');
if(phone.length!== 10 && 'type_efax_request' == 'change_existing_efax_account'){
alert("Phone number should be 10 digits for current eFax number");
return false;
}
}
the choice field name is type_efax_request, then the choices for it are:
change_existing_efax_account
request_new_efax_number
port_existing_number

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2018 07:12 AM
return true or false in your script to restrict or allow submit the form.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2018 12:31 AM
var _pNumber = "0123456789"
var flag = isValidPhoneNo(pNumber );
alert("flag: " + flag);
function isValidPhoneNo(phoneNumber){
var phoneNoRegEx = /^\d{10}$/;
if((phoneNumber.value.match(phoneNoRegEx)){
return true;
}
else{
alert("message");
return false;
}
}
//----------------------------------------------
like if this serve your requirement.