Latest 0.3.0
Homepage https://github.com/RainManGO/ValidateSwift
License MIT
Platforms ios 8.0
Authors

CI Status

Version
License
Platform

image

简介

使用起来超级简单的text验证框架,从此远离一堆代码验证一个表单。

示例

详细例子可以运行示例程序查看,克隆这个仓库,在Example文件夹下执行pod install

支持

  • iOS 8.0
  • Swift4.0+

CocoaPods安装

Podfile里添加:

pod 'ValidateSwift'

使用

单个TextFlied

  • 如果只需要验空

    passwordText.validate(emptyInfo: "请输入XX")

    emptyInfo参数可以不填,默认提示placeholder

  • 规则验证

    phoneText.validate(rulers: [Rulers.required,Rulers.phone]

多个TextFlied

首先需要遵守ValidateAble协议

class ValidateArrayViewController:ValidateAble{

}
  • 如果只需要验空

    if validateTexts(textsArray: [nameText,phoneText,emailText]){
    
    }

    更简单的方式,你还可以使用:(会深度遍历所有self.view的子TextFlied,如果没有就提示placeholder)

    if checkSubmitView(self.view){
    
    }
  • 规则验证

    if validateTexts(rulerTexts: getRulerText()) {
    
    }
    
    func getRulerText() -> [RulerText] {
           let passwordRulerText = RulerText.init(textfelid: passwordText, textRulers: [Rulers.required,Rulers.okpwd], emptyInfo: "请输入密码")
    
          let phoneRulerText = RulerText.init(textfelid: phoneText, textRulers: [Rulers.required,Rulers.phone])
    
          let emailRulerText = RulerText.init(textfelid: emailText, textRulers: [Rulers.required,Rulers.email])
    
          let idcardRulerText = RulerText.init(textfelid: idcardText, textRulers: [Rulers.required,Rulers.idcard])
    
          let numberRulerText = RulerText.init(textfelid: numberText, textRulers: [Rulers.number])
    
          return [passwordRulerText,phoneRulerText,emailRulerText,idcardRulerText,numberRulerText]
    }
    

目前支持规则

public enum Rulers:Int{
    case required = 0
    case phone
    case email
    case okpwd
    case idcard
    case bankcard
    case number
}

希望可以共同维护,遇到的多种规则,让它越来越强大,让验证越来越简单。

License

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

Latest podspec

{
    "name": "ValidateSwift",
    "version": "0.3.0",
    "summary": "A short description of ValidateSwift.",
    "homepage": "https://github.com/RainManGO/ValidateSwift",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "ZY": "[email protected]"
    },
    "source": {
        "git": "https://github.com/RainManGO/ValidateSwift.git",
        "tag": "0.3.0"
    },
    "swift_version": "4.2",
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "ValidateSwift/Classes/**/*"
}

Pin It on Pinterest

Share This