1

How can we define an input mask like $d,ddd.dd for data entry in a UITextField for an iPhone app?

Neeku
  • 3,646
  • 8
  • 33
  • 43
user927187
  • 33
  • 1
  • 4
  • possible duplicate of [Re-Apply currency formatting to a UITextField on a change event](http://stackoverflow.com/questions/2388448/re-apply-currency-formatting-to-a-uitextfield-on-a-change-event) – PengOne Sep 10 '11 at 19:49
  • possible duplicate of [Obj-C, iOS, how do I format a UITextField for currency international?](http://stackoverflow.com/questions/5850089/obj-c-ios-how-do-i-format-a-uitextfield-for-currency-international) – jscs Sep 10 '11 at 21:39

1 Answers1

3

You want to use an NSNumberFormatter to go back and forth between a value 1234.56 and a string @"$1,234.56".

Apple has a very good Data Formatting Guide to walk you through setting up and using a currency formatter.

In order to integrate this with a UITextField, you will want to use the delegate method

– textField:shouldChangeCharactersInRange:replacementString:

This allows you to validate and update characters as the user types them in. For an example of how to implement this, look at this post: Re-Apply currency formatting to a UITextField on a change event

Community
  • 1
  • 1
PengOne
  • 48,188
  • 17
  • 130
  • 149