• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
RE: Anyone have a phone number formatter?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Anyone have a phone number formatter?


  • Subject: RE: Anyone have a phone number formatter?
  • From: "David Aspinall" <email@hidden>
  • Date: Fri, 30 Mar 2007 07:08:19 -0700
  • Thread-topic: Anyone have a phone number formatter?

Title: RE: Anyone have a phone number formatter?

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: webobjects-dev-bounces+daspinall=email@hidden 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@hidden)
> Help/Unsubscribe/Update your Subscription:
> 40global-village.net
>
> This email sent to email@hidden
>

--

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@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Anyone have a phone number formatter? (From: Kevin Windham <email@hidden>)
 >Re: Anyone have a phone number formatter? (From: Chuck Hill <email@hidden>)

  • Prev by Date: Re: Network change
  • Next by Date: snapshot does not contain value for attribute named x with snapshot key: x ?
  • Previous by thread: Re: Anyone have a phone number formatter?
  • Next by thread: Re: Anyone have a phone number formatter?
  • Index(es):
    • Date
    • Thread