All Projects → orucanil → Stringformatter

orucanil / Stringformatter

Licence: mit
Simple Text Formetter (Credit Card Number, Phone Number, Serial Number etc.) Can be used in all text inputs according to the format pattern. If desired, large minor character restrictions can be made in the format pattern.

Programming Languages

swift
15916 projects
swift4
162 projects
swift3
66 projects

Projects that are alternatives of or similar to Stringformatter

ATGValidator
iOS validation framework with form validation support
Stars: ✭ 51 (-77.92%)
Mutual labels:  validator, credit-card, textfield
rust-phonenumber
Library for parsing, formatting and validating international phone numbers.
Stars: ✭ 99 (-57.14%)
Mutual labels:  formatter, phone-number, validator
dockerfile-utils
A library and command line interface for formatting and linting Dockerfiles.
Stars: ✭ 17 (-92.64%)
Mutual labels:  formatter, validator
LycricsTextView
No description or website provided.
Stars: ✭ 14 (-93.94%)
Mutual labels:  textview, textfield
Bankcardformat
💳 自动格式化银行卡号的EditText,卡号格式化、归属银行及卡别判断
Stars: ✭ 273 (+18.18%)
Mutual labels:  formatter, credit-card
FormToolbar
Simple, movable and powerful toolbar for UITextField and UITextView.
Stars: ✭ 85 (-63.2%)
Mutual labels:  textview, textfield
naija-phone-number
A fast minimal module to validate Nigerian mobile phone numbers using Regular Expressions.
Stars: ✭ 43 (-81.39%)
Mutual labels:  phone-number, validator
TTInputVisibilityController
Lightweight controller to keep your inputs visible when the keyboard is presented.
Stars: ✭ 21 (-90.91%)
Mutual labels:  textview, textfield
ThinCreditCard
💳 Simple way to add a credit card
Stars: ✭ 40 (-82.68%)
Mutual labels:  validator, textfield
Input Mask Ios
User input masking library repo.
Stars: ✭ 494 (+113.85%)
Mutual labels:  validator, formatter
Inputkit
📝InputKit, an Elegant Kit to limits your input text, inspired by BlocksKit, written in both Objective-C & ⚡️Swift.
Stars: ✭ 420 (+81.82%)
Mutual labels:  textview, textfield
Brazilian Utils
Utils library for specific Brazilian businesses
Stars: ✭ 1,023 (+342.86%)
Mutual labels:  validator, formatter
Tkkeyboardcontrol
TKKeyboardControl adds keyboard awareness and scrolling dismissal (like iMessages app) to any view with only 1 line of code for Swift.
Stars: ✭ 110 (-52.38%)
Mutual labels:  textview, textfield
CHRTextFieldFormatter
Provides UITextField formatting masks. Such as phone number and credit card number formatters.
Stars: ✭ 52 (-77.49%)
Mutual labels:  phone-number, textfield
Anyformatkit
Simple text formatting in Swift
Stars: ✭ 296 (+28.14%)
Mutual labels:  formatter, phone-number
Input Mask Android
User input masking library repo.
Stars: ✭ 1,060 (+358.87%)
Mutual labels:  validator, formatter
Credit Card
Credit Card Validation
Stars: ✭ 150 (-35.06%)
Mutual labels:  validator, credit-card
Routinator
An RPKI Validator written in Rust
Stars: ✭ 215 (-6.93%)
Mutual labels:  validator
Pp sql
Rails ActiveRecord SQL queries log beautifier
Stars: ✭ 223 (-3.46%)
Mutual labels:  formatter
Html Textview
TextView to display simple HTML
Stars: ✭ 2,445 (+958.44%)
Mutual labels:  textview

StringFormatter

Simple Text Formetter (Credit Card Number, Phone Number, Serial Number etc.) Can be used in all text inputs according to the format pattern. If desired, large minor character restrictions can be made in the format pattern.

Display Visual Example


Visual1

Installation

To use the StringFormatter extension in an app, just drag the StringFormatter extension file (demo files and assets are not needed) into your project.

Methods

The StringFormatter extension has the following methods (note: for iOS, String in method arguments):

  • func format(_ format: String, oldString: String) -> String

Formatting method according to given format pattern. oldString can be empty(""), but the final character formatting may not work smoothly.

  • func unformat(_ format: String, oldString: String) -> String

Unformatting method according to given format pattern. oldString can be empty(""), but the final character unformatting may not work smoothly.

How to use ?

If the text format is entered uppercase, the character input from the keyboard is displayed as a upper case character.

'x' or 'X' -> Any character

'c' or 'C' -> Alphabetic character

'n' or 'N' -> Numerical character



extension ViewController: UITextFieldDelegate {
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {

guard let text = textField.text else {
return true
}
let lastText = (text as NSString).replacingCharacters(in: range, with: string) as String

if textfieldPhoneNumber == textField {
textField.text = lastText.format("(NNN) NNN NN NN", oldString: text)
return false
} else if textfieldCreditCard == textField {
textField.text = lastText.format("nnnn nnnn nnnn nnnn", oldString: text)
return false
} else if textfieldSerialNumber == textField {
textField.text = lastText.format("XX NNNN", oldString: text)
return false
}
return true
}
}


Build and run the project files. Enjoy more examples!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].