Skip to main content

Hi,

I need UK phone numbers form jotform to be formatted to have country codes.

I tried this “replace with” function, screenshot below, but it couldn’t handle a number starting with 070… and replaced the second 0 with +44 as well. The entire record failed to reach ClickUp as a consequence.

It would be great if I could set it to replace just the first 0.

(Gemini’s suggestion of find ^0 didnt replace anything.)

I would also like it to send the record through with the phone number field blank if there is an error with the phone field.

Anyone know how to achieve this?

Cheers,

Dubs

 

 

 

 

 

 

Hi, @peedubs ,

 

You can use below Javascript code for this. I have assumed that the mobile number will always start from 0.

 

function formatUKPhoneNumber(phoneNumber) {
if (phoneNumber.startsWith("0")) {
return "+44" + phoneNumber.slice(1);
}
return phoneNumber;
}
let phoneNumber = inputData.phoneNumber;
let formattedNumber = formatUKPhoneNumber(phoneNumber);
output = {formattedNumber}

 

 

The above code will give output like +447087 000 123

 

Note - if you want to remove all the spaces you can replace 3rd line in the Javascript code to below 

 

return "+44" + phoneNumber.slice(1).replace(/\s+/g, "");

 

 


Hi Jay,

That worked!  Thank you so much :)

Many thanks

Paul


That’s awesome! Thank you @jayeshkumarbhatia for helping @peedubs!

If you have any other questions, please don’t hesitate to reach out to the Community. We’re always happy to help! 🤗


Hi, @peedubs ,

 

You can use below Javascript code for this. I have assumed that the mobile number will always start from 0.

 

function formatUKPhoneNumber(phoneNumber) {
if (phoneNumber.startsWith("0")) {
return "+44" + phoneNumber.slice(1);
}
return phoneNumber;
}
let phoneNumber = inputData.phoneNumber;
let formattedNumber = formatUKPhoneNumber(phoneNumber);
output = {formattedNumber}

 

 

The above code will give output like +447087 000 123

 

Note - if you want to remove all the spaces you can replace 3rd line in the Javascript code to below 

 

return "+44" + phoneNumber.slice(1).replace(/\s+/g, "");

 

 

 

I don’t suppose anyone knows how to make the output completely blank if there is no input to this field?  At the moment it outputs “()” which is throwing an error.  

Either that or is there a way in a zap to just ignore the step if it fails instead of breaking the whole zap?  Could this be done with error handling? 🙏🏻

 


Forget that,

I have just found you can do it with the formatter:

 

 


And for completion, I added the step before to remove the brackets from the number:

 

 

Hopefully this helps someone out one day 😊

 


We’re glad to hear that you have fixed the issue by using the Formatter step @peedubs! Also, thank you for sharing the setup here.

If you have any other questions, please don’t hesitate to reach out to the Community. We’re always happy to help! 🤗


Reply