Sellis Posted October 18, 2016 Share Posted October 18, 2016 So I have an interesting issue. My client needs to have text formatted like a phone number. A little background this client is using a braille translating service to convert a phone number to Grade 2 braille. so 617-555-1234 is represented like this. #fag-eee-abcd Here is what I need help doing. The text must always have (#) in the front to note that this is a number, and we must be bale to have the rule format the text like a number #fag-eee-abcd. We want to set the programming to be bale to accommodate the text entry of #fag-eee-abcd or #fageeeabcd. I tried modifying the format phone rule, but with little success, any one have any suggestions for this? Thank you Sean Quote Link to comment Share on other sites More sharing options...
step Posted October 18, 2016 Share Posted October 18, 2016 You could use a function like this one: function formatBraille(number) { // Remove any characters that aren't a-j // and consider the number a match if it has 7 or 10 letters in it number = number.replace(/[^a-j]/gi, '').match(/^(.{3})?(.{3})(.{4})$/); // If no match is found, return an empty string if (!number) return ''; // Remove the original string, leaving only the // captured groups in the 'matched' array number.shift(); // Remove any values that are 'undefined' and join with a hyphen return '#' + number.filter(Boolean).join('-'); } You can put that in your JavaScript Globals so that you can call it from any rule, or you can just put it in the same rule and call it like this: return formatBraille('fageeeabcd'); // #fag-eee-abcd If you wanted to take it a step further, you could have the function convert regular phone numbers into the braille format: function formatBraille(number) { number = number [color="Red"].split('') .map(function(s) { return /\d/.test(s) ? Chr(96 + Int(s)) : s; }) .join('')[/color] .replace(/[^a-j]/gi, '') .match(/^(.{3})?(.{3})(.{4})$/); if (!number) return ''; number.shift(); return '#' + number.filter(Boolean).join('-'); } Then you could pass either format and get the braille format back: return formatBraille('(617) 555-1234'); // #fag-eee-abcd Quote Link to comment Share on other sites More sharing options...
Sellis Posted October 20, 2016 Author Share Posted October 20, 2016 Thank you very much, this worked perfectly. With this code I was able to modify it to use another field is they leave it blank. Thank you Sean Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.