• 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: UITextField formatting for IP Address
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: UITextField formatting for IP Address


  • Subject: Re: UITextField formatting for IP Address
  • From: Andrew Farmer <email@hidden>
  • Date: Fri, 16 Oct 2009 21:46:41 -0700

On 16 Oct 2009, at 17:54, Alex Kac wrote:
Here is my code, btw. It works OK, but it still has the issue of moving the cursor to the end. Perhaps there is no way to do this on the iPhone - I just don't want to bang my head for hours.

- (void)formatForIP:(UITextField*)textField string:(NSString*)string
{
long long ip = [[string stringByReplacingOccurrencesOfString:@"." withString:@""] longLongValue];

NSNumberFormatter* numberFormatter = [[NSNumberFormatter alloc] init];
[numberFormatter setNumberStyle:NSNumberFormatterNoStyle];
[numberFormatter setPositiveFormat:@"###,###,###,###"];
[numberFormatter setGroupingSize:3];
[numberFormatter setSecondaryGroupingSize:3];
[numberFormatter setGroupingSeparator:@"."];
[numberFormatter setUsesGroupingSeparator:YES];


textField.text = [numberFormatter stringFromNumber:[NSNumber numberWithLongLong:ip]];
[numberFormatter release];
}

This isn't a valid approach to formatting IP addresses - it considers "12.34.56.78" to be equal to "12.345.678", which isn't even a valid address, let alone equivalent.
_______________________________________________


Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: UITextField formatting for IP Address
      • From: Alex Kac <email@hidden>
References: 
 >UITextField formatting for IP Address (From: Alex Kac <email@hidden>)
 >Re: UITextField formatting for IP Address (From: Alex Kac <email@hidden>)

  • Prev by Date: Re: Extract plain text content from a Text View
  • Next by Date: Re: How to retrieve the font information from TrueType font file?
  • Previous by thread: Re: UITextField formatting for IP Address
  • Next by thread: Re: UITextField formatting for IP Address
  • Index(es):
    • Date
    • Thread