Skip to content

KsiazeCienia/Validator-Swift

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 

Repository files navigation

Validator-Swift

Simple Swift Validator

Allows you to check if some String compare to ValidatorRule you created by adding validated(with: ValidatorRule) extension to String.

Rules type:

  • ValidatorRuleLength(rule: .maximumLength, value: 10) - word shorter than 10
  • ValidatorRuleLength(rule: .minimumLength, value: 5) - word longer than 5
  • ValidatorRulePattern(pattern: .email) - email
  • ValidatorRulePattern(pattern: .phoneNumber) - phone number
  • ValidatorRulePattern(dynamicString: {return dynamicWord}) - is equal to dynamic word

Usage example

  let word = "word"
  var dynamicWord = "dynamic"
  let dynamicRule = ValidatorRulePattern(dynamicString: {return dynamicWord})
  dynamicRule.set(errorMessage: "This two words are not equal")
  let result = word.validated(with: dynamicRule)
  switch result {
  case .invalid(let error):
    print(error)
  case .valid:
    print("valid")
  }

About

Simple validator for strings

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages