<commit_before># Swift Validation [![Build Status](https://travis-ci.org/joncottonskyuk/SwiftValidation.svg?branch=master)](https://travis-ci.org/joncottonskyuk/SwiftValidation)
Simple Validation library for Swift, adds validation directly to built in types String, Int, Double and Float

## Features
Adds the ability to validate String, Int, Double and Float values with basic validation rules out of the box. Also extends UITextField so you can easily test the validity of user input. The two base types `Validator` and `Validateable` are generic enough that they can be easily applied to any type, so you can add a set of validation rules for any custom type you create. Validation failures will throw 'multiple' errors, once for each failure, this allows you to quickly check a whole form of UITextFields for valid user input and report back all errors in a single pass.

## Installation

### Carthage [Github Repo](https://github.com/Carthage/Carthage)
Add the following line to your Cartfile
`github "joncottonskyuk/SwiftValidation"`

## Usage
The `Validateable` behaviour is applied directly to the built in `String` type, so to validate the value of a String, you can simply do...
```swift
// The following code prints "stringIsNotAValidEmailAddress" to console
do {
    let validEmailAddress = try "some<EMAIL>".validValue(.nonEmpty, .regex(StringValidationPattern.email))
} catch let errors as AggregateError {
    // AggregateError is a collection of ErrorType
    print(errors.reduce("", combine: { "\($0) \($1)" }))
} catch {
    // Some other error occurred
}
```

Validation can also be applied to unwrapped optionals, if the value is nil, an error will be thrown. If the value is valid, the optional will be unwrapped and the value will be returned.
```swift
// The following code prints "valueIsNil" to console
do {
    let goodOptionalString: String? = "Hello!"
    var badOptionalString: String?
    let validUnwrappedString = try goodOptionalString.validValue(.nonEmpty, .minimumLength(5)) // Passes
    let invalidString = try badOptionalString.validValue(.nonEmpty, .minimumLength(5)) // Fails because nil<commit_msg>Updated Carthage install instructions in README<commit_after># Swift Validation [![Build Status](https://travis-ci.org/joncottonskyuk/SwiftValidation.svg?branch=master)](https://travis-ci.org/joncottonskyuk/SwiftValidation)
Simple Validation library for Swift, adds validation directly to built in types String, Int, Double and Float

## Features
Adds the ability to validate String, Int, Double and Float values with basic validation rules out of the box. Also extends UITextField so you can easily test the validity of user input. The two base types `Validator` and `Validateable` are generic enough that they can be easily applied to any type, so you can add a set of validation rules for any custom type you create. Validation failures will throw 'multiple' errors, once for each failure, this allows you to quickly check a whole form of UITextFields for valid user input and report back all errors in a single pass.

## Installation

### [Carthage](https://github.com/Carthage/Carthage)
Add the following line to your Cartfile

`github "joncottonskyuk/SwiftValidation"`

## Usage
The `Validateable` behaviour is applied directly to the built in `String` type, so to validate the value of a String, you can simply do...
```swift
// The following code prints "stringIsNotAValidEmailAddress" to console
do {
    let validEmailAddress = try "some<EMAIL>".validValue(.nonEmpty, .regex(StringValidationPattern.email))
} catch let errors as AggregateError {
    // AggregateError is a collection of ErrorType
    print(errors.reduce("", combine: { "\($0) \($1)" }))
} catch {
    // Some other error occurred
}
```

Validation can also be applied to unwrapped optionals, if the value is nil, an error will be thrown. If the value is valid, the optional will be unwrapped and the value will be returned.
```swift
// The following code prints "valueIsNil" to console
do {
    let goodOptionalString: String? = "Hello!"
    var badOptionalString: String?
    let validUnwrappedString = try goodOptionalString.validValue(.nonEmpty, .minimumLength(5)) // Passes
    let invalidString = try badOptionalString.validValue(.nonEmpty, .minimumLength(5)) // Fails because nil
{'fraction_non_alphanumeric': 0.08323645663799116, 'fraction_numerical': 0.001860032550569635, 'mean_word_length': 4.74365821094793, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6730393', 'n_tokens_mistral': 1156, 'n_tokens_neox': 1115, 'n_words': 520}