A lightweight set of generic validation operators for Observable types
- Download Project
- Run:
pod install
- Drop 'RxSwiftValidator' into your project. I'll probably add Cocoapods and Carthage support when it becomes more mature. Note: SwiftValidator and RxSwift are dependencies so keep that in mind.
Feel free to contribute. I'll review pull requests asap.
// Email
Observable.just(validEmail).validate(StringRule.email).onValid().subscribe(onNext: { validated in
print("validated: \(validated)")
}).addDisposableTo(disposeBag)
Observable.just(invalidEmail).validate(StringRule.email).onValid().subscribe(onNext: { validated in
// Never
}).addDisposableTo(disposeBag)
Observable.just(validEmail).validate(StringRule.email).onInvalid().subscribe(onNext: { errors in
// Never
}).addDisposableTo(disposeBag)
Observable.just(invalidEmail).validate(StringRule.email).onInvalid().subscribe(onNext: { errors in
print(errors)
XCTAssert(errors.count > 0)
}).addDisposableTo(disposeBag)
// Phone number
Observable.just(validPhoneNumber).validate(StringRule.phoneNumber).onValid().subscribe(onNext: { validated in
print("validated: \(validated)")
XCTAssert(validPhoneNumber == validated)
}).addDisposableTo(disposeBag)
Observable.just(invalidPhoneNumber).validate(StringRule.phoneNumber).onValid().subscribe(onNext: { validated in
// Never
}).addDisposableTo(disposeBag)
Observable.just(validPhoneNumber).validate(StringRule.phoneNumber).onInvalid().subscribe(onNext: { errors in
// Never
}).addDisposableTo(disposeBag)
Observable.just(invalidPhoneNumber).validate(StringRule.phoneNumber).onInvalid().subscribe(onNext: { errors in
print(errors)
XCTAssert(errors.count > 0)
}).addDisposableTo(disposeBag)