99热99这里只有精品6国产,亚洲中文字幕在线天天更新,在线观看亚洲精品国产福利片 ,久久久久综合网

歡迎加入QQ討論群258996829

Swift 驗(yàn)證類庫 SwiftValidator

發(fā)布時(shí)間:2016-09-06 17:02  回復(fù):0  查看:5286  感興趣:55  贊:1   最后回復(fù):2016-09-06 17:02  

SwiftValidator 是一個(gè) Swift 的驗(yàn)證類庫,可以驗(yàn)證Email、電話號(hào)碼、郵政編碼等。

Swift 驗(yàn)證類庫 SwiftValidator

示例代碼:

Initialize the Validator by setting a delegate to a View Controller or other object.

// ViewController.swift
let validator = Validator()
Register the fields that you want to validate
override func viewDidLoad() {
    super.viewDidLoad()

    // Validation Rules are evaluated from left to right.
    validator.registerField(fullNameTextField, rules: [RequiredRule(), FullNameRule()])

    // You can pass in error labels with your rules
    // You can pass in custom error messages to regex rules (such as ZipCodeRule and EmailRule)
    validator.registerField(emailTextField, errorLabel: emailErrorLabel, rules: [RequiredRule(), EmailRule(message: "Invalid email")])

    // You can validate against other fields using ConfirmRule
    validator.registerField(emailConfirmTextField, errorLabel: emailConfirmErrorLabel, rules: [ConfirmationRule(confirmField: emailTextField)])

    // You can now pass in regex and length parameters through overloaded contructors
    validator.registerField(phoneNumberTextField, errorLabel: phoneNumberErrorLabel, rules: [RequiredRule(), MinLengthRule(length: 9)])
    validator.registerField(zipcodeTextField, errorLabel: zipcodeErrorLabel, rules: [RequiredRule(), ZipCodeRule(regex = "\\d{5}")])

    // You can unregister a text field if you no longer want to validate it
    validator.unregisterField(fullNameTextField)
}

相關(guān)開源代碼

您還未登錄,請(qǐng)先登錄

熱門帖子

最新帖子

?