Skip to content

Commit

Permalink
Merge branch 'master' into CardRules
Browse files Browse the repository at this point in the history
  • Loading branch information
RajatJain4061 committed Mar 8, 2019
2 parents 299bc4f + d414e15 commit 0739bf0
Show file tree
Hide file tree
Showing 19 changed files with 80 additions and 80 deletions.
12 changes: 10 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: objective-c
osx_image: xcode8
osx_image: xcode10.1
xcode_sdk: iphonesimulator10.0
xcode_project: Validator.xcodeproj
xcode_scheme: Validator
Expand All @@ -13,4 +13,12 @@ script:
- pod lib lint
after_success:

- bash <(curl -s https://codecov.io/bash)
- bash <(curl -s https://codecov.io/bash)


notifications:
webhooks:
urls:
- https://webhooks.gitter.im/e/4cfa929bd227586305cc
on_success: change # options: [always|never|change] default: always
on_failure: always # options: [always|never|change] default: always
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
SwiftValidator
===============

[![Build Status](https://travis-ci.org/jpotts18/SwiftValidator.svg?branch=travis-ci)](https://travis-ci.org/jpotts18/SwiftValidator) [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) [![codecov.io](https://codecov.io/github/jpotts18/SwiftValidator/coverage.svg?branch=master)](https://codecov.io/github/jpotts18/SwiftValidator?branch=master)
[![Build Status](https://travis-ci.org/SwiftValidatorCommunity/SwiftValidator.svg?branch=master)](https://travis-ci.org/SwiftValidatorCommunity/SwiftValidator) [![codecov.io](https://codecov.io/github/SwiftValidatorCommunity/SwiftValidator/coverage.svg?branch=master)](https://codecov.io/github/SwiftValidatorCommunity/SwiftValidator?branch=master)

Swift Validator is a rule-based validation library for Swift.

Expand Down Expand Up @@ -82,7 +82,7 @@ override func viewDidLoad() {

// 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}")])
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)
Expand All @@ -107,16 +107,16 @@ func validationSuccessful() {
// submit the form
}

func validationFailed(errors:[(Validatable ,ValidationError)]) {
// turn the fields to red
for (field, error) in errors {
if let field = field as? UITextField {
field.layer.borderColor = UIColor.redColor().CGColor
field.layer.borderWidth = 1.0
}
error.errorLabel?.text = error.errorMessage // works if you added labels
error.errorLabel?.hidden = false
}
func validationFailed(_ errors:[(Validatable ,ValidationError)]) {
// turn the fields to red
for (field, error) in errors {
if let field = field as? UITextField {
field.layer.borderColor = UIColor.red.cgColor
field.layer.borderWidth = 1.0
}
error.errorLabel?.text = error.errorMessage // works if you added labels
error.errorLabel?.isHidden = false
}
}

```
Expand Down Expand Up @@ -159,7 +159,7 @@ class SSNVRule: RegexRule {
```

## Documentation
Checkout the docs <a href="http://jpotts18.github.io/SwiftValidator/">here</a> via [@jazzydocs](https://twitter.com/jazzydocs).
Checkout the docs <a href="http://swiftvalidatorcommunity.github.io/SwiftValidator/">here</a> via [@jazzydocs](https://twitter.com/jazzydocs).


Credits
Expand Down
1 change: 1 addition & 0 deletions SwiftValidator.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Pod::Spec.new do |s|
s.name = "SwiftValidator"
s.version = "4.0.0"
s.swift_version = "4.2"
s.summary = "A UITextField Validation library for Swift"
s.homepage = "https://github.com/jpotts18/SwiftValidator"
s.screenshots = "https://raw.githubusercontent.com/jpotts18/SwiftValidator/master/swift-validator-v2.gif"
Expand Down
2 changes: 1 addition & 1 deletion SwiftValidator/Core/Validatable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public protocol Validatable {

extension UITextField: Validatable {

public var validationText: String {
open var validationText: String {
return text ?? ""
}
}
2 changes: 1 addition & 1 deletion SwiftValidator/Rules/ExactLengthRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class ExactLengthRule : Rule {
- returns: A boolean value. True if validation is successful; False if validation fails.
*/
public func validate(_ value: String) -> Bool {
return value.characters.count == length
return value.count == length
}

/**
Expand Down
2 changes: 1 addition & 1 deletion SwiftValidator/Rules/FloatRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class FloatRule:Rule {
public func validate(_ value: String) -> Bool {
let regex = try? NSRegularExpression(pattern: "^[-+]?(\\d*[.])?\\d+$", options: [])
if let regex = regex {
let match = regex.numberOfMatches(in: value, options: [], range: NSRange(location: 0, length: value.characters.count))
let match = regex.numberOfMatches(in: value, options: [], range: NSRange(location: 0, length: value.count))
return match == 1
}
return false
Expand Down
2 changes: 1 addition & 1 deletion SwiftValidator/Rules/FullNameRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class FullNameRule : Rule {
- returns: A boolean value. True if validation is successful; False if validation fails.
*/
public func validate(_ value: String) -> Bool {
let nameArray: [String] = value.characters.split { $0 == " " }.map { String($0) }
let nameArray: [String] = value.split { $0 == " " }.map { String($0) }
return nameArray.count >= 2
}

Expand Down
12 changes: 6 additions & 6 deletions SwiftValidator/Rules/ISBNRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class ISBNRule: Rule {
fatalError("Invalid ISBN sanitizing regex")
}

let sanitized = regex.stringByReplacingMatches(in: value, options: [], range: NSMakeRange(0, value.characters.count), withTemplate: "")
let sanitized = regex.stringByReplacingMatches(in: value, options: [], range: NSMakeRange(0, value.count), withTemplate: "")

return ISBN10Validator().verify(sanitized) || ISBN13Validator().verify(sanitized)
}
Expand Down Expand Up @@ -140,15 +140,15 @@ private struct ISBN10Validator: ISBNValidator {
var checksum = 0

for i in 0..<9 {
if let intCharacter = Int(String(input[input.characters.index(input.startIndex, offsetBy: i)])) {
if let intCharacter = Int(String(input[input.index(input.startIndex, offsetBy: i)])) {
checksum += (i + 1) * intCharacter
}
}

if (input[input.characters.index(input.startIndex, offsetBy: 9)] == "X") {
if (input[input.index(input.startIndex, offsetBy: 9)] == "X") {
checksum += 10 * 10
} else {
if let intCharacter = Int(String(input[input.characters.index(input.startIndex, offsetBy: 9)])) {
if let intCharacter = Int(String(input[input.index(input.startIndex, offsetBy: 9)])) {
checksum += 10 * intCharacter
}
}
Expand Down Expand Up @@ -176,13 +176,13 @@ private struct ISBN13Validator: ISBNValidator {
var checksum = 0

for i in 0..<12 {
if let intCharacter = Int(String(input[input.characters.index(input.startIndex, offsetBy: i)])) {
if let intCharacter = Int(String(input[input.index(input.startIndex, offsetBy: i)])) {
print("\(factor[i%2]) * \(intCharacter)")
checksum += factor[i % 2] * intCharacter
}
}

if let lastInt = Int(String(input[input.characters.index(input.startIndex, offsetBy: 12)])) {
if let lastInt = Int(String(input[input.index(input.startIndex, offsetBy: 12)])) {
return (lastInt - ((10 - (checksum % 10)) % 10) == 0)
}

Expand Down
2 changes: 1 addition & 1 deletion SwiftValidator/Rules/MaxLengthRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class MaxLengthRule: Rule {
- returns: A boolean value. True if validation is successful; False if validation fails.
*/
public func validate(_ value: String) -> Bool {
return value.characters.count <= DEFAULT_LENGTH
return value.count <= DEFAULT_LENGTH
}

/**
Expand Down
2 changes: 1 addition & 1 deletion SwiftValidator/Rules/MinLengthRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class MinLengthRule: Rule {
- returns: A boolean value. True if validation is successful; False if validation fails.
*/
public func validate(_ value: String) -> Bool {
return value.characters.count >= DEFAULT_LENGTH
return value.count >= DEFAULT_LENGTH
}

/**
Expand Down
6 changes: 3 additions & 3 deletions SwiftValidator/Rules/RegexRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Foundation
/**
`RegexRule` is a subclass of Rule that defines how a regular expression is validated.
*/
public class RegexRule : Rule {
open class RegexRule : Rule {
/// Regular express string to be used in validation.
private var REGEX: String = "^(?=.*?[A-Z]).{8,}$"
/// String that holds error message.
Expand All @@ -35,7 +35,7 @@ public class RegexRule : Rule {
- parameter value: String to checked for validation.
- returns: Boolean value. True if validation is successful; False if validation fails.
*/
public func validate(_ value: String) -> Bool {
open func validate(_ value: String) -> Bool {
let test = NSPredicate(format: "SELF MATCHES %@", self.REGEX)
return test.evaluate(with: value)
}
Expand All @@ -45,7 +45,7 @@ public class RegexRule : Rule {
- returns: String of error message.
*/
public func errorMessage() -> String {
open func errorMessage() -> String {
return message
}
}
6 changes: 3 additions & 3 deletions SwiftValidator/Rules/RequiredRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Foundation
/**
`RequiredRule` is a subclass of Rule that defines how a required field is validated.
*/
public class RequiredRule: Rule {
open class RequiredRule: Rule {
/// String that holds error message.
private var message : String

Expand All @@ -31,7 +31,7 @@ public class RequiredRule: Rule {
- parameter value: String to check for validation.
- returns: Boolean value. True if validation is successful; False if validation fails.
*/
public func validate(_ value: String) -> Bool {
open func validate(_ value: String) -> Bool {
return !value.isEmpty
}

Expand All @@ -40,7 +40,7 @@ public class RequiredRule: Rule {
- returns: String of error message.
*/
public func errorMessage() -> String {
open func errorMessage() -> String {
return message
}
}
35 changes: 22 additions & 13 deletions Validator.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@
attributes = {
LastSwiftMigration = 0700;
LastSwiftUpdateCheck = 0700;
LastUpgradeCheck = 0820;
LastUpgradeCheck = 0930;
ORGANIZATIONNAME = jpotts18;
TargetAttributes = {
62D1AE161A1E6D4400E4DFF8 = {
Expand Down Expand Up @@ -592,14 +592,22 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand Down Expand Up @@ -627,6 +635,7 @@
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.2;
};
name = Debug;
};
Expand All @@ -638,14 +647,22 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand All @@ -664,7 +681,8 @@
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_VERSION = 4.2;
VALIDATE_PRODUCT = YES;
};
name = Release;
Expand All @@ -678,7 +696,6 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "me.jeffpotter.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -692,7 +709,6 @@
PRODUCT_BUNDLE_IDENTIFIER = "me.jeffpotter.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand All @@ -709,8 +725,6 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "me.jeffpotter.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Validator.app/Validator";
};
name = Debug;
Expand All @@ -724,15 +738,14 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "me.jeffpotter.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Validator.app/Validator";
};
name = Release;
};
FB465CCC1B9884F400398388 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
CODE_SIGN_IDENTITY = "";
CURRENT_PROJECT_VERSION = 1;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEFINES_MODULE = YES;
Expand All @@ -750,7 +763,6 @@
PRODUCT_BUNDLE_IDENTIFIER = "me.jeffpotter.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = "1,2";
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
Expand All @@ -760,7 +772,7 @@
FB465CCD1B9884F400398388 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
CODE_SIGN_IDENTITY = "";
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 1;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
Expand All @@ -776,7 +788,6 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = "1,2";
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
Expand All @@ -801,7 +812,6 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.levous.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Validator.app/Validator";
};
name = Debug;
Expand All @@ -822,7 +832,6 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.levous.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Validator.app/Validator";
};
name = Release;
Expand Down
Loading

0 comments on commit 0739bf0

Please sign in to comment.