Skip to content

falcaoaugustos/CPF_CNPJ-Mask

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CPF_CNPJ-Mask

Format your input text with a CPF / CNPJ mask. You can add a custom mask too.

Preview

ANIMATION_01

Installation

Manually

  1. Download and drop InputTextMask.swift in your project.
  2. Congratulations!

Usage

Getting Started

Clone this repository:

$ git clone https://github.com/falcaoaugustos/CPF_CNPJ-Mask.git

Open the CPF_CNPJ-Mask.xcodeproj file and build to see the example project.

Example

Look at an example which editing a UITextField text attribute:

func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
  if  textField.text.count == 14, string.count > 0 {
    return false
  }

  textField.text = string.count < 1 ?
    InputTextMask.applyMask(.CPF, toText: String(textField.text!.dropLast())) :
    InputTextMask.applyMask(.CPF, toText: textField.text! + string)

  return false
}

Customization

You can add a new pattern updating the MaskType enum:

public enum MaskType: String {
  case CPF = "***.***.***-**"
  case CNPJ = "**.***.***/****-**"
  case birthday = "**/**/****"
}

Contributing

Contributions are very welcome! If you'd like to contribute, feel free to send a pull request!

License

CPF_CNPJ-Mask is released under an MIT license. See LICENSE file for more information.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages