I have a text field where the user enters data. It's a phone number field. If the user enters 1234567890
, I want it displayed as (123)-(456)-7890
as the user types. How is this possible?
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- xcode 4 garbage collection removed?
- Xcode: Is there a way to change line spacing (UI L
- Unable to process app at this time due to a genera
- Swift - hide pickerView after value selected
The code bellow is what I typically use. The format is different but you get the picture. This will handle input such as '123df#$@$gdfg45-+678dfg901' and output '1 (234) 567-8901'
This will help you
Format (xxx) xxx-xxxx For SWIFT 3.0
For those of you who require international number formatting: https://code.google.com/p/libphonenumber/
Comes with C++, Java and JavaScript implementations. Should be easy to wrap the C++ implementations in a .mm file and write a small Objective-C wrapper around it.
SWIFT
A valid option is https://github.com/iziz/libPhoneNumber-iOS All the other answer cover only a small part of the possibilities and combinations, this library actually parse and validate EVERY phone number, and identify: