Well it has been a while since I have posted anything mainly because I have been busy at work trying to get a new version of our application completed and into production.
I am going to try and post a couple of items that I have had to deal with lately that caused me some issues. The first item I am going to look at is a custom phone number formatter, I build it out of a need to allowing the user to enter just about anything in there and have the system properly format the phone number with an extension.
I did the usual Google search and saw different pieces but never really liked any single one. So what I came up with is a custom phone number formatter that extends mx.formatters.PhoneFormatter. The format function basically checks to see the length of the phone number and performs the formatting based on the length.
If the length is 0 or less than 10, we place an error in the error variable and clear out the phone number
if( phoneNbr.length == 0 || phoneNbr.length < 10)
{
error="Invalid Length Phone Number";
phoneNbr = "";
}
If the length is 10 then we basically return the phone number that is formatted by the supper's format.
However if the length is greater than 10 we then strip off any spaces and ()-.x in the number then reassemble the phone number into a (###) ###-#### x#### format the x#### will basically pick up the remaining characters.
I hope this is of some help to everyone.
if you're already checking to see if length is less than 10, there's no need to check if it is equal to 0.
ReplyDelete