Message formatting is hard with Exchange WebMail (sucks) but here is a method 
we use to strip out the garbage and then submit the different parsed values for 
area code, number and extension.


/** assumes the phone number is "(111)  222-  3333   extension 444" which we 
reduce to 1112223333444 and then split up */
public void setFullPhoneNumer( String value )
{
        if ( value != null )
        {
                /** remove everything except numbers */
                String reduced = value.replaceAll("^1|\\D+", 
Const.EMPTY_STRING);
                
                int len = reduced.length();
                if ( len >= 10 )
                {
                        validateTakeValueForKeyPath( reduced.substring( 0, 3 ), 
"phoneAreaCode" );
                        validateTakeValueForKeyPath( 
reduced.replaceAll("^(\\d{3})(\\d{3})(\\d{4})(\\d*)", "$2$3"), "phoneNumber");

                        // this will insert a dash in the phone number, depends 
how you want to store the value
                        // 
reduced.replaceAll("^(\\d{3})(\\d{3})(\\d{4})(\\d*)", "$2-$3"), "phoneNumber");
                        
                        if ( len > 10 )
                                validateTakeValueForKeyPath( reduced.substring( 
10 ), "phoneExtension" );
                }
                else
                        throw new NSValidation.ValidationException( "Invalid 
phone number" );
        }
}


-----Original Message-----
From: [EMAIL PROTECTED] on behalf of Chuck Hill
Sent: Thu 3/29/2007 8:09 PM
To: Kevin Windham
Cc: WebObjects Dev Apple
Subject: Re: Anyone have a phone number formatter?
 
If you just want output formatting (and not input parsing), it can be  
as simple as this:

     public StringBuffer format(Object object, StringBuffer  
stringBuffer, FieldPosition fieldPosition)
     {
         if (object instanceof Number)
         {
             stringBuffer.append(((Number)object).intValue() == 2 ?  
"Y" : "");
         }

         return stringBuffer;
     }



     /**
      * @throw RuntimeException parseObject is not implemented
      */
     public Object parseObject(String arg0, ParsePosition arg1)
     {
         throw new RuntimeException("parseObject is not implemented");
     }


This is an output formatter that takes a number formats this to "Y"  
if the value is 2 and to an empty string for all other values.  Don't  
ask, legacy data.

Chuck




On Mar 29, 2007, at 4:58 PM, Kevin Windham wrote:

> I am looking for info on how to create a formatter for phone  
> numbers. I have surmised that I am supposed to use java.text.format  
> in some fashion, but I am having trouble finding any examples.
>
> Does anyone have any examples they can share, or can point me to  
> some better info than the java docs on the class.
>
> Thanks,
> Kevin
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Webobjects-dev mailing list      ([email protected])
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/webobjects-dev/chill% 
> 40global-village.net
>
> This email sent to [EMAIL PROTECTED]
>

-- 

Practical WebObjects - for developers who want to increase their  
overall knowledge of WebObjects or who are trying to solve specific  
problems.
http://www.global-village.net/products/practical_webobjects





 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/daspinall%40ticoon.com

This email sent to [EMAIL PROTECTED]

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to