I need a code to add a feature to my funnels. I would like to set a prefix to the phone number field. For example “+57” in order to the customer don’t write the country code. This prefix can not to be delete by the customer.
An additional wanted feature is the phone number field only accept numeric characters and having a fixed long.
Hello @idelasotta ,
First of all, extremely sorry for the long delay on this, this thread was buried under our recent posts. and thank you for reminding us through the direct chat.
Here is the code you can use to enforce a phone number prefix:
<script>
const PHONE_PREFIX = "+56";
document.querySelectorAll('input[name="phone"]').forEach(i=>{
if (!i.value) i.value = PHONE_PREFIX;
if (!i.value.startsWith(PHONE_PREFIX)) {
i.value = PHONE_PREFIX + i.value.replace('+','');
}
i.dataset.oldPhone=i.value;
i.addEventListener('input', (e)=>{
if (!i.value.startsWith(PHONE_PREFIX) && i.dataset.oldPhone && i.dataset.oldPhone.startsWith(PHONE_PREFIX)) {
i.value = i.dataset.oldPhone;
}
i.dataset.oldPhone = i.value;
})
})
</script>
How it works?
-
Copy the code above as it is into your page Custom Codes > Body JS.
-
You can modify the phone prefix on the first line if needed ‘
PHONE_PREFIX’"+56" -
Save changes and take it for a spin, do let us know if it needs any improvement.
Hey there ![]()
Just adding a quick update here, as this thread is quite old and a lot has changed since then.
The good news is that in Funnelish, you don’t need custom code for this anymore ![]()
We’ve introduced much more flexibility in the editor, especially around phone inputs and country-related fields. Everything can now be handled directly within Funnelish — no need to load external country code lists or rely on custom scripts.
We’ve also created an updated guide that shows exactly how to set this up:
Country Code for Phone Numbers (New Funnelish Update)
If you need a hand with this (or anything else), just let us know — happy to help!
