nothing too crazy, but might be handy if anyone out there needs to do this (as I did).
/** * Formats raw input to ###-##-#### format * @param {String} raw Source string to format * @return {String} The formatted string */ PMDUtils.FormatSsn = function PMDUtils_formatSsn(raw) { Guard.NotNullOrEmpty(raw, 'A valid ssn string is required'); var newString = []; var currCharCode; var delimiter = '-'; // Copy only the numeric characters into a clean buffer for(var i = 0, len = raw.length, j = 0; i < len ; i++) { currCharCode = raw.charCodeAt(i); // Character codes for ints 1 - 9 are 48 - 57 if (j < 9 && currCharCode >= 48 && currCharCode <= 57) { newString.push(raw.charAt(i)); if(j === 2 || j === 4) { newString.push(delimiter); } j++; } } return newString.join(''); }