https://github.com/rainmango/validateswift
ValidateSwift ValidateText
https://github.com/rainmango/validateswift
validate validaterswift validator
Last synced: 11 months ago
JSON representation
ValidateSwift ValidateText
- Host: GitHub
- URL: https://github.com/rainmango/validateswift
- Owner: RainManGO
- License: mit
- Created: 2019-04-19T10:14:14.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-10-11T07:35:14.000Z (over 6 years ago)
- Last Synced: 2025-04-11T13:00:15.184Z (11 months ago)
- Topics: validate, validaterswift, validator
- Language: Swift
- Homepage:
- Size: 669 KB
- Stars: 9
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ValidateSwift
[](https://travis-ci.org/776210576@qq.com/ValidateSwift)
[](https://cocoapods.org/pods/ValidateSwift)
[](https://cocoapods.org/pods/ValidateSwift)
[](https://cocoapods.org/pods/ValidateSwift)

## 简介
使用起来超级简单的text验证框架,从此远离一堆代码验证一个表单。
## 示例
详细例子可以运行示例程序查看,克隆这个仓库,在Example文件夹下执行`pod install`
## 支持
- iOS 8.0
- Swift4.0+
## CocoaPods安装
Podfile里添加:
```ruby
pod 'ValidateSwift'
```
## 使用
### 单个TextFlied
- 如果只需要验空
```swift
passwordText.validate(emptyInfo: "请输入XX")
```
emptyInfo参数可以不填,默认提示placeholder
- 规则验证
```swift
phoneText.validate(rulers: [Rulers.required,Rulers.phone]
```
### 多个TextFlied
首先需要遵守`ValidateAble`协议
```swift
class ValidateArrayViewController:ValidateAble{
}
```
- 如果只需要验空
```swift
if validateTexts(textsArray: [nameText,phoneText,emailText]){
}
```
更简单的方式,你还可以使用:(会深度遍历所有self.view的子TextFlied,如果没有就提示placeholder)
```swift
if checkSubmitView(self.view){
}
```
- 规则验证
```swift
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]
}
```
### 目前支持规则
```swift
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.