Coder Social home page Coder Social logo

mbtextfieldwithinputvalidator's Introduction

MBTextFieldWithInputValidator

设计**来源于部门总监,目前项目中使用的是OC的版本,用Swift又实现了一遍,然后对某些细节进行了优化。

功能

实现对UITextField输入内容进行验证的功能,如果内容不符合验证策略,则弹出错误信息提示用户

主要特点

1.采用Swift语言编写。

2.单个验证器的实现采用策略模式,使用者可以通过继承MBInputValidator,重写func validateInput(input:UITextField) -> ErrorDesc?方法即可实现自己的验证策略。目前已经实现了如下几种验证器

  • MBEmptyInputValidator:判断内容是否为空
  • MBAlphabetInputValidator:判断内容是否是英文字母
  • MBNumberInputValidator:判断内容是否是数字
  • MBPhoneInputValidator:判断内容是否是手机号
  • MBPasswordInputValidator:判断内容是否是6-12位字母或数字组成的密码

3.为同一个UITextField指定多个验证器采用了链式的方式(具体指定方法参见demo),验证器可以在代码中指定,也可以在Xib/Storyboard中指定,验证时只需要调用通用的验证方法即可,实现验证策略对业务功能开发者的透明。

4.因为UIAlertView将在iOS9中废除,所以采用了UIAlertController,又因为需要拿到UITextField所在的ViewController才能弹出UIAlertController,所以为UIView实现了获取其ViewController的extension。

mbtextfieldwithinputvalidator's People

Contributors

mmoaay avatar

Watchers

James Cloos avatar raybon.lee avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.