Discussions
Stay up-to-date with the latest news from NetSuite. You’ll be in the know about how to connect with peers and take your business to new heights at our virtual, in-person, on demand events, and much more.
New AI Community Guidelines. Please review and follow them to ensure AI use stays safe, accurate, and compliant.
Code Snippet: Formatting a social security number
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(''); }
Steve Klett | Senior Developer
NetValue Technology
0