Objective-C Bridge for Honour Validation library
Bridge classes to allow you to use Honour in Objective-C projects.
Validator.mustBe(Uppercase()).andMust(StartsWith("F")).validate("FOOBAR")Turns to:
[[[HBValidator mustBe:[HBUppercase new]] andMust:[[HBStartsWith alloc] initWithValue:@"F"]] validate:@"FOOBAR"];NSString *username = @"jeanpimentel";
[[HBLowercase new] validate:username];It is possible to use validators in a chain.
NSString *username = @"jeanpimentel";
HBValidator *v = [HBValidator new];
[v addRule:[HBLowercase new]];
[v addRule:[HBNoWhitespace new]];
[v addRule:[[HBLength alloc] initWithMin:3 max:60]];
[v validate:username]; // YES
// or
[[v addRule:[HBLowercase new]] addRule:[HBNoWhitespace new]] addRule:[[HBLength alloc] initWithMin:3 max:60]];
[v validate:username]; // YESIt is possible to use some syntax tricks to be highly expressive.
HBValidator *v = [[[HBValidator mustHave:[[HBLength alloc] initWithMin:3 max:60]]
and:[HBNoWhitespace new]]
andMustBe:[HBLowercase new]];
[v validate:@"jeanpimentel"]; // YESWe have 3 validation methods
validate()- returns YES or NOassert()- returns a instance of HBAssertResult that contains the result YES/NO and all errors, if any.check()- returns a instance of HBCheckResult that contains the result YES/NO and the first error, if any.
- (BOOL)validate:(NSString *)value;HBValidator *validator = [[HBValidator alloc] init];
[validator addRule:[[HBUppercase alloc] init]];
[validator addRule:[[HBStartsWith alloc] initWithValue:@"J"]];
[validator validate:@"JEAN"]; // YES
[validator validate:@"PIMENTEL"]; // NO- (HBAssertResult *)assert:(NSString *)value;HBValidator *validator = [[HBValidator alloc] init];
[validator addRule:[[HBUppercase alloc] init]];
[validator addRule:[[HBStartsWith alloc] initWithValue:@"J"]];
HBAssertResult *result = [validator assert:@"JEAN"];
result.isValid // YES
result.invalidRules // [] (empty)
HBAssertResult *result = [validator assert:@"Jean"];
result.isValid // NO
result.invalidRules // [HBUppercase*]
HBAssertResult *result = [validator assert:@"Felipe"];
result.isValid // NO
result.invalidRules // [HBUppercase*, HBStartsWith*]- (HBCheckResult *)check:(NSString *)value;HBValidator *validator = [[HBValidator alloc] init];
[validator addRule:[[HBUppercase alloc] init]];
[validator addRule:[[HBStartsWith alloc] initWithValue:@"J"]];
HBAssertResult *result = [validator assert:@"JEAN"];
result.isValid // YES
result.invalidRule // nil
HBAssertResult *result = [validator assert:@"Felipe"];
result.isValid // NO
result.invalidRule // HBUppercase*
HBAssertResult *result = [validator assert:@"FELIPE"];
result.isValid // NO
result.invalidRule // HBStartsWith*| HonourBridge Version | Minimum iOS Target | Notes |
|---|---|---|
| 0.1.1 | iOS 7 | Swift 1.2 (Xcode 6.3) is required. |
-
If you found a bug, and can provide steps to reliably reproduce it, open an issue.
-
If you have a feature request, open an issue.
-
If you want to contribute, submit a pull request.
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature - Commit your changes:
git commit -am 'Add some feature' - Push to the branch:
git push origin my-new-feature - Submit a pull request
Always a working in progress...
Available now:
- AlwaysInvalid
- AlwaysValid
- Contains
- EndsWith
- Length
- Lowercase
- NoWhitespace
- NotEmpty
- Regex
- Roman
- StartsWith
- Uppercase
- Version
Localized validators
- Brazil (BR)
- CPF
HonourBridge is released under the MIT license. See LICENSE for details.