VMaskTextField is a library which create an input mask for iOS.

Overview

VMaskTextField

CI Status Version License Platform

An inputmask helps the user with the input by ensuring a predefined format. This can be useful for dates, numerics, phone numbers etc

demo

Usage

@interface VViewController ()

@property (weak,nonatomic) IBOutlet VMaskTextField * maskTextField;

@end

@implementation VViewController

- (void)viewDidLoad{
    //Telephone with Code Area
    self.maskTextField.mask = @"(##) ####-####";
    self.maskTextField.delegate = self;
}

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
   return  [_maskTextField shouldChangeCharactersInRange:range replacementString:string];
}

@end

Features

  • Validating data type
  • Flexible masks
  • Automatic maxlength

Installation

VMaskTextField is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "VMaskTextField"

or copy VMaskTextField.h and VMaskTextField.m to your project folder.

Author

viniciusmo, [email protected]

License

VMaskTextField is available under the MIT license. See the LICENSE file for more info.

Comments
  • Implementation of `raw` property

    Implementation of `raw` property

    This pull request implements the return of raw property. Some users related that this property always returns nil (#11), it happens for me too.

    Another thing is to clear the text before setTextWithMask:. If you set a string in interface builder, for example, when you call setTextWithMask the new text appends the old text (setted in interface builder). For example:

    • Your mask is "##-##-##";
    • You set the VMaksTextField text with 12 in interface builder;
    • You call [self.textField setTextWithMask:@"098765"];
    • The final result is 12-09-87.

    Semantically, setText will replace all text.

    opened by danielborges93 4
  • Erro na MASK

    Erro na MASK

    Vinicius, eu adicionei a MASK em apenas um textfield, que foi a data, porém na mesma view tem outros textfields que mantive o padrão.

    Porém acho que a função sobrescreve a do textfields, e nenhum outro textfield sem mascaram funcionam.

    @IBOutlet weak var data: VMaskTextField!

    override func viewDidLoad() { super.viewDidLoad() data.mask = "##/##/####" data.delegate = self

     descricao.delegate  = self
     price.delegate      = self
     size.delegate       = self
    }
    

    func textField(textField: VMaskTextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool { return data.shouldChangeCharactersInRange(range, replacementString: string); }

    Pode me ajudar? Obrigado

    opened by thiagoleaowd 4
  • Pre-populate formatted phone text field

    Pre-populate formatted phone text field

    How do I pre-populate a phone formatted text field with a phone number I am storing online without any formatting characters?

    For example userObj.phone = "2125551212"

    When I try the following in viewDidLoad phoneTextField.mask = @"(###) ###-####"; phoneTextField.text = userObj.phone;

    My screen displays 2125551212

    When I try phoneTextField.mask = @"(###) ###-####"; [phoneTextField shouldChangeCharactersInRange:NSMakeRange(0, phoneTextField.text.length) replacementString:userObj.phone];

    My screen displays (125) 121-2125551212

    opened by petec029 3
  • Add possibility to disallow editing between characters.

    Add possibility to disallow editing between characters.

    There is a situation, when user types something to the masked text field, then he moves cursor to middle of text and edit it. I don't know if this is not a bug, but I guess developer should have at least a possibility to disallow edition between characters.

    opened by aperechnev 1
  • Add possibility to disallow editing between characters.

    Add possibility to disallow editing between characters.

    There is a situation, when user enters something to the masked text field, then he moves cursor to middle of text and edit it. I don't know if this is not a bug, but I guess developer should have at least a possibility to disallow edition between characters.

    opened by aperechnev 1
  • Unknown class VMaskTextField in interface builder file (using Pods installation)

    Unknown class VMaskTextField in interface builder file (using Pods installation)

    I followed the installation guide, everything is fine, outlets setup, but when viewDidLoad gets called, it breaks with the following message:

    "Unknown class VMaskTextField in interface builder file" -> I have defined the class for the textfield using Identity Inspector

    I've deleted from the Pods and just paste the VMaskTextField class into my project. All config the same, then it works. So, I think it can be something related to the Pods.

    Best Regards,

    Sidan

    opened by sidan 1
  • fixed a bug where it behaved unexpectedly when the mask contained number

    fixed a bug where it behaved unexpectedly when the mask contained number

    When textField.mask is set to a string that includes numbers (e.g "0(###) ### ## ##"), textField takes multiple inputs when a single character is entered.

    opened by halileohalilei 1
  • Run function after text field ends editing

    Run function after text field ends editing

    func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool {
      let maskTextField = textField as? VMaskTextField
    
      if range.location == 17 && range.length == 0 {
        self.function()
      }
    
      return maskTextField!.shouldChangeCharactersInRange(range, replacementString: string)
    }
    

    I know that after it's 17th symbol added, i need to run the function. so I have to run it after return. How to do it properly using methods? Do i have to rewrite anything in library, like add a completion block? (I use swift in my project and don't know how to properly add completion block in here, so can you help me some way?)

    opened by AgapovOne 0
  • Error range, shouldChangeCharactersInRange

    Error range, shouldChangeCharactersInRange

    • (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { return [_txtPass shouldChangeTextInRange:range replacementText: string]; }

    Error range, 'Sending NSRange (aka 'struct_NSRange') to parameter of incompatible type 'UITextRange * _Nonnull'

    opened by popularizan 0
  • Wrong masking when setting text programmatically

    Wrong masking when setting text programmatically

    Trying to set a phone number programmatically before the user starts typing manually but the results are always wrong. When using textfield.text = ... directly, no mask is applied. When using setTextWithMask: the following happens:

    Mask = "(###) ###-####" Text needed: 1234567890, also tried (123) 456-7890 Result: (234) 789-0 Expected: (123) 456-7890

    I found a solution in the mean time by setting the text one character at a time:

    phoneText.characters.forEach({
        let text = phoneTextField.text ?? ""
        phoneTextField.setTextWithMask( text + String($0) )
    })
    
    opened by juanpdelat 3
  • VMaskTextField  addTarget forControlEvents:UIControlEventEditingChanged

    VMaskTextField addTarget forControlEvents:UIControlEventEditingChanged

    @viniciusmo , any ideas, why textField add target not working!

    VMaskTextField *textField
    [textField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
    
    -(void)textFieldDidChange :(UITextField *)theTextField{
        NSLog( @"text changed: %@", theTextField.text);
    }
    
    
    opened by KanybekMomukeyev 2
  • raw property always returns nil

    raw property always returns nil

    I figured that the raw property would return the value of the textfield without the mask, but not only it doesn't do that, it always returns nil.

    I checked the code, and raw is never actually used other than inside the rawTo methods, but those always return 0 as well...

    opened by jlubeck 1
Owner
Vinícius Oliveira
Vinícius Oliveira
VKPinCodeView is simple and elegant UI component for input PIN. You can easily customise appearance and get auto fill (OTP) iOS 12 feature right from the box.

Features Variable PIN length Underline, border and custom styles The error status with / without shake animation Resetting the error status manually,

Vladimir Kokhanevich 95 Nov 24, 2022
A Float Input View with smooth animation and supporting icon and seperator written with Swift

RSFloatInputView Features Smooth animation using CoreText Support optional left icon Support optional seperator Configurable padding, size, fonts and

null 103 Nov 13, 2022
UITextField-based control for (NS)Measurement values input.

MeasurementTextField UITextField-based control for (NS)Measurement values input. Provides type-safe keyboard and picker based input of different measu

Siarhei Fiedartsou 16 Jul 22, 2021
An auto growing text input bar for messaging apps.

ALTextInputBar An auto growing text input bar for messaging apps. Written in Swift. ALTextInputBar is designed to solve a few issues that folks usuall

Alex Littlejohn 265 Nov 15, 2022
A simple and easily customizable InputAccessoryView for making powerful input bars with autocomplete and attachments

InputBarAccessoryView Features Autocomplete text with @mention, #hashtag or any other prefix A self-sizing UITextView with an optional fixed height (c

Nathan Tannar 968 Jan 2, 2023
🔍 An elegant search controller which replaces the UISearchController for iOS (iPhone & iPad) .

?? An elegant search controller for iOS. QQ chat room Features Support a variety of hot search style Support a variety of search history style Support

mamba 3.8k Jan 8, 2023
A custom TextField with a switchable icon which shows or hides the password and enforce good password policies

PasswordTextField A custom TextField with a switchable icon which shows or hides the password and enforces good password policies, written in Swift. ⭐

Chris Jimenez 304 Dec 29, 2022
Text entry controls which contain a built-in title/label so that you don't have to add a separate title for each field.

FloatLabelFields Overview Installation Via Interface Builder Via Code Credits Additional References Questions Overview FloatLabelFields is the Swift i

Fahim Farook 1.2k Jan 4, 2023
An `NSTextField` that specifies a maximum count after which text is highlighted to indicate an overflow

DSFMaxLengthDisplayTextField An NSTextField that specifies a maximum count after which text is highlighted to indicate an overflow Why? I always liked

Darren Ford 3 Aug 1, 2022
AEOTPTextField - A beautiful iOS OTP Text Field library, written in Swift with full access customization in UI.

AEOTPTextField - A beautiful iOS OTP Text Field library, written in Swift with full access customization in UI.

Abdelrhman Kamal 79 Jan 3, 2023
⚡️ A library of widgets and helpers to build instant-search applications on iOS.

By Algolia. InstantSearch family: InstantSearch iOS | InstantSearch Android | React InstantSearch | InstantSearch.js | Angular InstantSearch | Vue Ins

Algolia 568 Jan 4, 2023
Custom emoji rendering library for iOS apps with support for GIF & still images

Custom emoji rendering library for iOS apps with support for GIF & still images - plug-in extension for UITextView - performance, cache ✅ - Made with ?? by @GetStream

Stream 244 Dec 11, 2022
StyledTextKit is a declarative attributed string library for fast rendering and easy string building.

StyledTextKit is a declarative attributed string library for fast rendering and easy string building. It serves as a simple replacement to NSAttribute

GitHawk 1.2k Dec 23, 2022
Library that allows you binding `enabled` property of button with textable elements (TextView, TextField)

What is NxEnabled? It's a fairly common case, when the enabled state of button depends on some textable elements such as TextView, TextField. So this

Nikita Ermolenko 33 Sep 20, 2021
RichTextKit is a Swift-based library for working with rich text in UIKit, AppKit and SwiftUI.

About RichTextKit RichTextKit is a Swift-based library that lets you work with rich text in UIKit, AppKit and SwiftUI. RichTextKit is under developmen

Daniel Saidi 282 Dec 28, 2022
A customisable view for entering arbitrary length pins, codes or passwords in iOS. Supports iOS 12 one time codes.

CBPinEntryView CBPinEntryView is a view written in Swift to allow easy and slick entry of pins, codes or passwords. It allows backspacing, dismissal o

Chris Byatt 183 Dec 5, 2022
A SwiftUI TextField with a prompt (or placeholder) that floats above the text field when active or not empty. Requires iOS 15.

FloatingPromptTextField A prompt is the label in a text field that informs the user about the kind of content the text field expects. In a default Tex

Emilio Peláez 43 Nov 3, 2022
Focus text field in SwiftUI dynamically and progress through form using iOS keyboard.

Focuser Focuser allows to focus SwiftUI text fields dynamically and implements ability move go through the form using Keyboard for iOS 13 and iOS 14.

Art Technologies 118 Dec 25, 2022
Provides a SwiftUI multi-line TextView implementation including support for auto-sizing. (iOS)

TextView Also available as a part of my SwiftUI+ Collection – just add it to Xcode 13+ Provides a SwiftUI multi-line TextView implementation with supp

SwiftUI+ 51 Jan 3, 2023