在 Zapier 中格式化 phone 数字(代码)
Format phone number in Zapier (code)
这里是 JS 新手!在此先感谢您的帮助!
我正在尝试在 Zapier 中格式化 phone 号码。数据来自 webhook,格式通常为“2223334444”。我需要确认此格式,然后在数字前面添加 1 以用于 Twilio 集成。 My attempted code is attached
您应该使用正则表达式:
function convertPhone(phone)
{
if (!phone.match(/1?2{3}3{3}4{4}/)
return null;
// check in case humber has a prefix of 1:
return phone.match(/.+/)? phone: 1 + phone;
}
您实际上可以使用内置格式化程序格式化 phone 数字:https://zapier.com/help/formatter/。它比 运行 通过代码步骤更好一点,因为 phone 数字将根据 format/standard 您 select 的任何内容进行验证和格式化,即使输入格式不同也是如此。
这里是 JS 新手!在此先感谢您的帮助!
我正在尝试在 Zapier 中格式化 phone 号码。数据来自 webhook,格式通常为“2223334444”。我需要确认此格式,然后在数字前面添加 1 以用于 Twilio 集成。 My attempted code is attached
您应该使用正则表达式:
function convertPhone(phone)
{
if (!phone.match(/1?2{3}3{3}4{4}/)
return null;
// check in case humber has a prefix of 1:
return phone.match(/.+/)? phone: 1 + phone;
}
您实际上可以使用内置格式化程序格式化 phone 数字:https://zapier.com/help/formatter/。它比 运行 通过代码步骤更好一点,因为 phone 数字将根据 format/standard 您 select 的任何内容进行验证和格式化,即使输入格式不同也是如此。