You're reading our legacy documentation, the documentation for deprecated versions of UserFrosting. To read the docs for the current version of UserFrosting, visit learn.userfrosting.com.

    Useful helpers for HandlebarsJS

    /**
     * format a string as a 7- or 10-digit phone number using regular expressions.
     * usage: {{phoneNumberFormat phone_number}}
     */
    Handlebars.registerHelper("phoneNumberFormat", function(phoneNumber) {  
        // Strip out all non-digit characters
        phoneNumber = phoneNumber.replace(/[^0-9]/g, '');
        // Format as a 7- or 10- digit phone number
        var len = phoneNumber.length;
        if (len == 7)
            phoneNumber = phoneNumber.replace(/([0-9]{3})([0-9]{4})/g, '$1-$2');
        else if (len == 10)
            phoneNumber = phoneNumber.replace(/([0-9]{3})([0-9]{3})([0-9]{4})/g, '($1) $2-$3'); 
        return phoneNumber; 
    });