title: UITextField Currency Format Left to Right
body: <p>I want to format my UITextField with having a <code>$</code> on the left when I enter an amount.</p>
  
  <p>So far what my code does is when I enter let says <code>$5.65</code> this is how it's entered: <code>$0.05</code> -> <code>$0.56</code> -> <code>$5.65</code></p>
  
  <p>I want it so that it's not right to left but left to right so something like this: <code>$5</code> -> <code>$5.</code> -> <code>$5.6</code> -> <code>$5.65</code></p>
  
  <p>But I want to restrict it to only two decimals place, the dollar sign is on the left, and you can not type any other characters (e.g: !,@,#,$,%,^, A-Z')</p>
  
  <p>This is what I have currently:</p>
  
  <pre><code>func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -&gt; Bool {
  
      let text: NSString = (textField.text ?? "") as NSString
      let finalString = text.replacingCharacters(in: range, with: string)
  
      // 'currency' is a String extension that doews all the number styling
      amuTextField.text = finalString.currency
  
      // returning 'false' so that textfield will not be updated here, instead from styling extension
      return false
  }
  
  func currencyInputFormatting() -&gt; String {
  
      var number: NSNumber!
      let formatter = NumberFormatter()
      formatter.numberStyle = .currencyAccounting
      formatter.currencySymbol = "$"
      formatter.maximumFractionDigits = 2
      formatter.minimumFractionDigits = 2
  
      var amountWithPrefix = self
  
      // remove from String: "$", ".", ","
      let regex = try! NSRegularExpression(pattern: "[^0-9]", options: .caseInsensitive)
      amountWithPrefix = regex.stringByReplacingMatches(in: amountWithPrefix, options: NSRegularExpression.MatchingOptions(rawValue: 0), range: NSMakeRange(0, self.characters.count), withTemplate: "")
  
      let double = (amountWithPrefix as NSString).doubleValue
      number = NSNumber(value: (double / 100))
  
      return formatter.string(from: number)!
  }
  </code></pre>