Data Not Saving in Correct Format in Live

Hi. I added some basic JavaScript to make sure that phone numbers were formatted properly.
I’ll include the code below, but it basically just uses an onChange() event to makes sure a phone number is formatted 555-555-5555. It works fine in preview and in the live site after pubishing.

The weird thing is that it is saved to the database incorrectly in the live, but not in preview.

  • In Preview: 555-555-5555 is added to the database in that format.
  • In Live: 555-555-5555 is added to the database as 5555555555

No clue why there would be a difference. Any ideas?

Here’s the code, if that’s helpful.


function formatPhoneNumber(phoneNumberString) {
    let cleaned = ('' + phoneNumberString).replace(/\D/g, '')
    let match = cleaned.match(/^(\d{3})(\d{3})(\d{4})$/)
    if (match) {
        return `${match[1]}-${match[2]}-${match[3]}`
    }
    return null
}

export function input3_change(event) {
    // This function was added from the Properties & Events panel. To learn more, visit http://wix.to/UcBnC-4
    let number = $w('#input3').value;
    number = formatPhoneNumber(number);
    if (number) {
        $w('#input3').value = number;
    }
}