mirror of
https://github.com/zhigang1992/RETableViewManager.git
synced 2026-06-14 10:09:11 +08:00
Move example project to CocoaPods
This commit is contained in:
19
RETableViewManagerExample/Pods/REValidation/LICENSE
generated
Normal file
19
RETableViewManagerExample/Pods/REValidation/LICENSE
generated
Normal file
@@ -0,0 +1,19 @@
|
||||
Copyright (c) 2013 Roman Efimov (https://github.com/romaonthego).
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
166
RETableViewManagerExample/Pods/REValidation/README.md
generated
Normal file
166
RETableViewManagerExample/Pods/REValidation/README.md
generated
Normal file
@@ -0,0 +1,166 @@
|
||||
# REValidation
|
||||
|
||||
Simple Objective-C object validation.
|
||||
|
||||
Currently available default validators:
|
||||
|
||||
> * Presence validator
|
||||
* String length validator
|
||||
* Email validator
|
||||
|
||||
## Requirements
|
||||
* Xcode 4.5 or higher
|
||||
* Apple LLVM compiler
|
||||
* iOS 5.0 or higher / Mac OS X 10.7 or higher
|
||||
* ARC
|
||||
|
||||
## Installation
|
||||
|
||||
### CocoaPods
|
||||
|
||||
The recommended approach for installating `REValidation` is via the [CocoaPods](http://cocoapods.org/) package manager, as it provides flexible dependency management and dead simple installation.
|
||||
For best results, it is recommended that you install via CocoaPods >= **0.15.2** using Git >= **1.8.0** installed via Homebrew.
|
||||
|
||||
Install CocoaPods if not already available:
|
||||
|
||||
``` bash
|
||||
$ [sudo] gem install cocoapods
|
||||
$ pod setup
|
||||
```
|
||||
|
||||
Change to the directory of your Xcode project:
|
||||
|
||||
``` bash
|
||||
$ cd /path/to/MyProject
|
||||
$ touch Podfile
|
||||
$ edit Podfile
|
||||
```
|
||||
|
||||
Edit your Podfile and add REValidation:
|
||||
|
||||
``` bash
|
||||
pod 'REValidation', '~> 0.1.1'
|
||||
```
|
||||
|
||||
Install into your Xcode project:
|
||||
|
||||
``` bash
|
||||
$ pod install
|
||||
```
|
||||
|
||||
Open your project in Xcode from the .xcworkspace file (not the usual project file)
|
||||
|
||||
``` bash
|
||||
$ open MyProject.xcworkspace
|
||||
```
|
||||
|
||||
Please note that if your installation fails, it may be because you are installing with a version of Git lower than CocoaPods is expecting. Please ensure that you are running Git >= **1.8.0** by executing `git --version`. You can get a full picture of the installation details by executing `pod install --verbose`.
|
||||
|
||||
### Manual Install
|
||||
|
||||
All you need to do is drop `REValidation` files into your project, and add `#include "REValidation.h"` to the top of classes that will use it.
|
||||
|
||||
## Example Usage
|
||||
|
||||
``` objective-c
|
||||
[REValidation registerDefaultValidators];
|
||||
[REValidation registerDefaultErrorMessages];
|
||||
|
||||
NSString *emailString = @"test#@example.com";
|
||||
NSArray *errors = [REValidation validateObject:emailString name:@"Email" validators:@[ @"presence", @"length(3, 20)", @"email" ]];
|
||||
|
||||
for (NSError *error in errors)
|
||||
NSLog(@"Error: %@", error.localizedDescription);
|
||||
|
||||
// Alternatively you can use REValidator instances
|
||||
//
|
||||
NSString *testString = @"";
|
||||
errors = [REValidation validateObject:testString name:@"Test string" validators:@[ [REPresenceValidator validator], [RELengthValidator validatorWithParameters:@{ @"min": @3, @"max": @10}] ]];
|
||||
|
||||
for (NSError *error in errors)
|
||||
NSLog(@"Error: %@", error.localizedDescription);
|
||||
```
|
||||
|
||||
It's easy to implement a custom validator, you need to subclass from `REValidator` and implement three methods:
|
||||
|
||||
```objective-c
|
||||
+ (NSString *)name;
|
||||
+ (NSDictionary *)parseParameterString:(NSString *)string;
|
||||
+ (NSError *)validateObject:(NSString *)object variableName:(NSString *)name parameters:(NSDictionary *)parameters;
|
||||
```
|
||||
|
||||
For example:
|
||||
|
||||
```objective-c
|
||||
+ (NSString *)name
|
||||
{
|
||||
return @"length";
|
||||
}
|
||||
|
||||
+ (NSDictionary *)parseParameterString:(NSString *)string
|
||||
{
|
||||
NSError *error = NULL;
|
||||
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"(\\d+)" options:0 error:&error];
|
||||
NSArray *matches = [regex matchesInString:string options:0 range:NSMakeRange(0, string.length)];
|
||||
NSMutableArray *results = [NSMutableArray array];
|
||||
for (NSTextCheckingResult *matchResult in matches) {
|
||||
NSString *match = [string substringWithRange:[matchResult range]];
|
||||
[results addObject:match];
|
||||
}
|
||||
if (results.count == 2) {
|
||||
return @{ @"min": results[0], @"max": results[1]};
|
||||
}
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
+ (NSError *)validateObject:(NSString *)object variableName:(NSString *)name parameters:(NSDictionary *)parameters
|
||||
{
|
||||
NSUInteger minimumValue = [parameters[@"min"] integerValue];
|
||||
NSUInteger maximumValue = [parameters[@"max"] integerValue];
|
||||
|
||||
if (object.length < minimumValue && minimumValue > 0)
|
||||
return [NSError re_validationErrorForDomain:@"com.REValidation.minimumLength", name, minimumValue];
|
||||
|
||||
if (object.length > maximumValue && maximumValue > 0)
|
||||
return [NSError re_validationErrorForDomain:@"com.REValidation.maximumLength", name, maximumValue];
|
||||
|
||||
return nil;
|
||||
}
|
||||
```
|
||||
|
||||
It's possible to add validations without subclassing `REValidator` class using inline validations. Here's an example that shows how to use inline validations with [RETableViewManager](https://github.com/romaonthego/RETableViewManager):
|
||||
|
||||
```objective-c
|
||||
REValidator *nameValidator = [REValidator validator];
|
||||
nameValidator.inlineValidation = ^NSError *(NSString *string, NSString *name) {
|
||||
if ([string componentsSeparatedByString:@" "].count < 2) {
|
||||
return [NSError errorWithDomain:@"" code:0 userInfo:@{NSLocalizedDescriptionKey: @"Please enter first and last name."}];
|
||||
}
|
||||
return nil;
|
||||
};
|
||||
|
||||
RETextItem *nameItem = [RETextItem itemWithTitle:@"" value:self.contact.name placeholder:@"First & Last Name"];
|
||||
nameItem.autocapitalizationType = UITextAutocapitalizationTypeWords;
|
||||
nameItem.validators = @[nameValidator];
|
||||
```
|
||||
|
||||
## Contact
|
||||
|
||||
Roman Efimov
|
||||
|
||||
- https://github.com/romaonthego
|
||||
- https://twitter.com/romaonthego
|
||||
- romefimov@gmail.com
|
||||
|
||||
## License
|
||||
|
||||
REValidation is available under the MIT license.
|
||||
|
||||
Copyright © 2013 Roman Efimov.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
32
RETableViewManagerExample/Pods/REValidation/REValidation/NSError+REValidation.h
generated
Normal file
32
RETableViewManagerExample/Pods/REValidation/REValidation/NSError+REValidation.h
generated
Normal file
@@ -0,0 +1,32 @@
|
||||
//
|
||||
// NSError+REValidation.h
|
||||
// REValidation
|
||||
//
|
||||
// Copyright (c) 2013 Roman Efimov (https://github.com/romaonthego)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface NSError (REValidation)
|
||||
|
||||
+ (NSError *)re_validationErrorForDomain:(NSString *)domain, ...;
|
||||
|
||||
@end
|
||||
40
RETableViewManagerExample/Pods/REValidation/REValidation/NSError+REValidation.m
generated
Normal file
40
RETableViewManagerExample/Pods/REValidation/REValidation/NSError+REValidation.m
generated
Normal file
@@ -0,0 +1,40 @@
|
||||
//
|
||||
// NSError+REValidation.m
|
||||
// REValidation
|
||||
//
|
||||
// Copyright (c) 2013 Roman Efimov (https://github.com/romaonthego)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
//
|
||||
|
||||
#import "NSError+REValidation.h"
|
||||
#import "REValidation.h"
|
||||
|
||||
@implementation NSError (REValidation)
|
||||
|
||||
+ (NSError *)re_validationErrorForDomain:(NSString *)domain, ...
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, domain);
|
||||
NSError *error = [NSError errorWithDomain:domain code:0 userInfo:@{ NSLocalizedDescriptionKey:[[NSString alloc] initWithFormat:[REValidation errorMessageForDomain:domain] arguments:args] }];
|
||||
va_end(args);
|
||||
return error;
|
||||
}
|
||||
|
||||
@end
|
||||
60
RETableViewManagerExample/Pods/REValidation/REValidation/REValidation.h
generated
Normal file
60
RETableViewManagerExample/Pods/REValidation/REValidation/REValidation.h
generated
Normal file
@@ -0,0 +1,60 @@
|
||||
//
|
||||
// REValidation.h
|
||||
// REValidation
|
||||
//
|
||||
// Copyright (c) 2013 Roman Efimov (https://github.com/romaonthego)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "REValidator.h"
|
||||
#import "NSError+REValidation.h"
|
||||
#import "REPresenceValidator.h"
|
||||
#import "RELengthValidator.h"
|
||||
#import "REEmailValidator.h"
|
||||
#import "REURLValidator.h"
|
||||
|
||||
@interface REValidation : NSObject
|
||||
|
||||
///-----------------------------
|
||||
/// @name Registering Validators
|
||||
///-----------------------------
|
||||
|
||||
+ (void)registerDefaultValidators;
|
||||
+ (void)registerDefaultErrorMessages;
|
||||
+ (void)registerValidator:(Class)validatorClass;
|
||||
|
||||
///-----------------------------
|
||||
/// @name Validating Objects
|
||||
///-----------------------------
|
||||
|
||||
+ (NSError *)validateObject:(NSObject *)object name:(NSString *)name validatorString:(NSString *)string;
|
||||
+ (NSError *)validateObject:(NSObject *)object name:(NSString *)name validator:(REValidator *)validator;
|
||||
+ (NSArray *)validateObject:(NSObject *)object name:(NSString *)name validators:(NSArray *)validators;
|
||||
|
||||
///-----------------------------
|
||||
/// @name Handling Error Messages
|
||||
///-----------------------------
|
||||
|
||||
+ (NSString *)errorMessageForDomain:(NSString *)domain;
|
||||
+ (void)setErrorMessage:(NSString *)message forDomain:(NSString *)domain;
|
||||
+ (void)setErrorMessages:(NSDictionary *)messages;
|
||||
|
||||
@end
|
||||
146
RETableViewManagerExample/Pods/REValidation/REValidation/REValidation.m
generated
Normal file
146
RETableViewManagerExample/Pods/REValidation/REValidation/REValidation.m
generated
Normal file
@@ -0,0 +1,146 @@
|
||||
//
|
||||
// REValidation.m
|
||||
// REValidation
|
||||
//
|
||||
// Copyright (c) 2013 Roman Efimov (https://github.com/romaonthego)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
//
|
||||
|
||||
#import "REValidation.h"
|
||||
|
||||
@interface REValidation ()
|
||||
|
||||
@property (strong, readwrite, nonatomic) NSMutableDictionary *registeredValidators;
|
||||
@property (strong, readwrite, nonatomic) NSMutableDictionary *errorMessages;
|
||||
|
||||
@end
|
||||
|
||||
@implementation REValidation
|
||||
|
||||
+ (instancetype)sharedObject
|
||||
{
|
||||
static REValidation *_sharedClient = nil;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
_sharedClient = [[REValidation alloc] init];
|
||||
});
|
||||
|
||||
return _sharedClient;
|
||||
}
|
||||
|
||||
+ (void)registerValidator:(Class)validatorClass
|
||||
{
|
||||
[REValidation sharedObject].registeredValidators[[validatorClass name]] = NSStringFromClass(validatorClass);
|
||||
}
|
||||
|
||||
+ (void)registerDefaultValidators
|
||||
{
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
[REValidation registerValidator:[REPresenceValidator class]];
|
||||
[REValidation registerValidator:[RELengthValidator class]];
|
||||
[REValidation registerValidator:[REEmailValidator class]];
|
||||
[REValidation registerValidator:[REURLValidator class]];
|
||||
});
|
||||
}
|
||||
|
||||
+ (void)registerDefaultErrorMessages
|
||||
{
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
NSDictionary *messages = @{
|
||||
@"com.REValidation.presence": @"%@ can't be blank.",
|
||||
@"com.REValidation.minimumLength": @"%@ is too short (minimum is %i characters).",
|
||||
@"com.REValidation.maximumLength": @"%@ is too long (maximum is %i characters).",
|
||||
@"com.REValidation.email": @"%@ is not a valid email.",
|
||||
@"com.REValidation.url": @"%@ is not a valid url."
|
||||
};
|
||||
[REValidation sharedObject].errorMessages = [NSMutableDictionary dictionaryWithDictionary:messages];
|
||||
});
|
||||
}
|
||||
|
||||
+ (NSString *)errorMessageForDomain:(NSString *)domain
|
||||
{
|
||||
return NSLocalizedString([REValidation sharedObject].errorMessages[domain], [REValidation sharedObject].errorMessages[domain]);
|
||||
}
|
||||
|
||||
+ (void)setErrorMessage:(NSString *)message forDomain:(NSString *)domain
|
||||
{
|
||||
[REValidation sharedObject].errorMessages[domain] = message;
|
||||
}
|
||||
|
||||
+ (void)setErrorMessages:(NSDictionary *)messages
|
||||
{
|
||||
[REValidation sharedObject].errorMessages = [NSMutableDictionary dictionaryWithDictionary:messages];
|
||||
}
|
||||
|
||||
+ (NSError *)validateObject:(NSObject *)object name:(NSString *)name validatorString:(NSString *)string
|
||||
{
|
||||
NSString *validatorStringName = [string componentsSeparatedByString:@"("][0];
|
||||
for (NSString *validatorName in [REValidation sharedObject].registeredValidators) {
|
||||
if ([validatorName isEqualToString:validatorStringName]) {
|
||||
Class validator = NSClassFromString([REValidation sharedObject].registeredValidators[validatorName]);
|
||||
return [[validator class] validateObject:object variableName:name parameters:[validator parseParameterString:string]];
|
||||
}
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
+ (NSError *)validateObject:(NSObject *)object name:(NSString *)name validator:(REValidator *)validator
|
||||
{
|
||||
return [[validator class] validateObject:object variableName:name parameters:validator.parameters];
|
||||
}
|
||||
|
||||
+ (NSArray *)validateObject:(NSObject *)object name:(NSString *)name validators:(NSArray *)validators
|
||||
{
|
||||
NSMutableArray *errors = [NSMutableArray array];
|
||||
|
||||
for (id validator in validators) {
|
||||
NSError *error;
|
||||
if ([validator isKindOfClass:[NSString class]]) {
|
||||
error = [self validateObject:object name:name validatorString:(NSString *)validator];
|
||||
} else {
|
||||
REValidator *v = (REValidator *)validator;
|
||||
if (v.inlineValidation) {
|
||||
error = [[v class] validateObject:object variableName:name validation:v.inlineValidation];
|
||||
} else {
|
||||
error = [self validateObject:object name:name validator:validator];
|
||||
}
|
||||
}
|
||||
if (error)
|
||||
[errors addObject:error];
|
||||
}
|
||||
|
||||
return errors;
|
||||
}
|
||||
|
||||
|
||||
- (id)init
|
||||
{
|
||||
self = [super init];
|
||||
if (!self)
|
||||
return nil;
|
||||
|
||||
self.registeredValidators = [[NSMutableDictionary alloc] init];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
||||
55
RETableViewManagerExample/Pods/REValidation/REValidation/REValidator.h
generated
Normal file
55
RETableViewManagerExample/Pods/REValidation/REValidation/REValidator.h
generated
Normal file
@@ -0,0 +1,55 @@
|
||||
//
|
||||
// REValidator.h
|
||||
// REValidation
|
||||
//
|
||||
// Copyright (c) 2013 Roman Efimov (https://github.com/romaonthego)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface REValidator : NSObject
|
||||
|
||||
@property (strong, readonly, nonatomic) NSDictionary *parameters;
|
||||
@property (copy, readwrite, nonatomic) NSError *(^inlineValidation)(id object, NSString *name);
|
||||
|
||||
///-----------------------------
|
||||
/// @name Getting Validator Instance
|
||||
///-----------------------------
|
||||
|
||||
+ (instancetype)validator;
|
||||
+ (instancetype)validatorWithParameters:(NSDictionary *)parameters;
|
||||
+ (instancetype)validatorWithInlineValidation:(NSError *(^)(id object, NSString *name))validation;
|
||||
|
||||
///-----------------------------
|
||||
/// @name Configuring Representation
|
||||
///-----------------------------
|
||||
|
||||
+ (NSString *)name;
|
||||
+ (NSDictionary *)parseParameterString:(NSString *)string;
|
||||
|
||||
///-----------------------------
|
||||
/// @name Validating Objects
|
||||
///-----------------------------
|
||||
|
||||
+ (NSError *)validateObject:(NSObject *)object variableName:(NSString *)name parameters:(NSDictionary *)parameters;
|
||||
+ (NSError *)validateObject:(NSObject *)object variableName:(NSString *)name validation:(NSError *(^)(id object, NSString *name))validation;
|
||||
|
||||
@end
|
||||
77
RETableViewManagerExample/Pods/REValidation/REValidation/REValidator.m
generated
Normal file
77
RETableViewManagerExample/Pods/REValidation/REValidation/REValidator.m
generated
Normal file
@@ -0,0 +1,77 @@
|
||||
//
|
||||
// REValidator.m
|
||||
// REValidation
|
||||
//
|
||||
// Copyright (c) 2013 Roman Efimov (https://github.com/romaonthego)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
//
|
||||
|
||||
#import "REValidator.h"
|
||||
|
||||
@interface REValidator ()
|
||||
|
||||
@property (strong, readwrite, nonatomic) NSDictionary *parameters;
|
||||
|
||||
@end
|
||||
|
||||
@implementation REValidator
|
||||
|
||||
+ (instancetype)validator
|
||||
{
|
||||
return [[self alloc] init];
|
||||
}
|
||||
|
||||
+ (instancetype)validatorWithParameters:(NSDictionary *)parameters
|
||||
{
|
||||
REValidator *validator = [[self alloc] init];
|
||||
validator.parameters = parameters;
|
||||
return validator;
|
||||
}
|
||||
|
||||
+ (instancetype)validatorWithInlineValidation:(NSError *(^)(id object, NSString *name))validation
|
||||
{
|
||||
REValidator *validator = [[self alloc] init];
|
||||
validator.inlineValidation = validation;
|
||||
return validator;
|
||||
}
|
||||
|
||||
+ (NSString *)name
|
||||
{
|
||||
return @"";
|
||||
}
|
||||
|
||||
+ (NSError *)validateObject:(NSObject *)object variableName:(NSString *)name parameters:(NSDictionary *)parameters
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
+ (NSError *)validateObject:(NSObject *)object variableName:(NSString *)name validation:(NSError *(^)(id object, NSString *name))validation
|
||||
{
|
||||
if (validation)
|
||||
return validation(object, name);
|
||||
return nil;
|
||||
}
|
||||
|
||||
+ (NSDictionary *)parseParameterString:(NSString *)string
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
@end
|
||||
30
RETableViewManagerExample/Pods/REValidation/REValidation/Validators/REEmailValidator.h
generated
Normal file
30
RETableViewManagerExample/Pods/REValidation/REValidation/Validators/REEmailValidator.h
generated
Normal file
@@ -0,0 +1,30 @@
|
||||
//
|
||||
// REEmailValidator.h
|
||||
// REValidation
|
||||
//
|
||||
// Copyright (c) 2013 Roman Efimov (https://github.com/romaonthego)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
//
|
||||
|
||||
#import "REValidator.h"
|
||||
|
||||
@interface REEmailValidator : REValidator
|
||||
|
||||
@end
|
||||
52
RETableViewManagerExample/Pods/REValidation/REValidation/Validators/REEmailValidator.m
generated
Normal file
52
RETableViewManagerExample/Pods/REValidation/REValidation/Validators/REEmailValidator.m
generated
Normal file
@@ -0,0 +1,52 @@
|
||||
//
|
||||
// REEmailValidator.m
|
||||
// REValidation
|
||||
//
|
||||
// Copyright (c) 2013 Roman Efimov (https://github.com/romaonthego)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
//
|
||||
|
||||
#import "REEmailValidator.h"
|
||||
#import "REValidation.h"
|
||||
|
||||
@implementation REEmailValidator
|
||||
|
||||
+ (NSString *)name
|
||||
{
|
||||
return @"email";
|
||||
}
|
||||
|
||||
+ (NSError *)validateObject:(NSString *)object variableName:(NSString *)name parameters:(NSDictionary *)parameters
|
||||
{
|
||||
NSString *string = object ? object : @"";
|
||||
if (string.length == 0)
|
||||
return nil;
|
||||
|
||||
NSError *error = NULL;
|
||||
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}" options:NSRegularExpressionCaseInsensitive error:&error];
|
||||
NSTextCheckingResult *match = [regex firstMatchInString:string options:0 range:NSMakeRange(0, string.length)];
|
||||
|
||||
if (!match)
|
||||
return [NSError re_validationErrorForDomain:@"com.REValidation.email", name];
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
@end
|
||||
30
RETableViewManagerExample/Pods/REValidation/REValidation/Validators/RELengthValidator.h
generated
Normal file
30
RETableViewManagerExample/Pods/REValidation/REValidation/Validators/RELengthValidator.h
generated
Normal file
@@ -0,0 +1,30 @@
|
||||
//
|
||||
// RELengthValidator.h
|
||||
// REValidation
|
||||
//
|
||||
// Copyright (c) 2013 Roman Efimov (https://github.com/romaonthego)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
//
|
||||
|
||||
#import "REValidator.h"
|
||||
|
||||
@interface RELengthValidator : REValidator
|
||||
|
||||
@end
|
||||
67
RETableViewManagerExample/Pods/REValidation/REValidation/Validators/RELengthValidator.m
generated
Normal file
67
RETableViewManagerExample/Pods/REValidation/REValidation/Validators/RELengthValidator.m
generated
Normal file
@@ -0,0 +1,67 @@
|
||||
//
|
||||
// RELengthValidator.m
|
||||
// REValidation
|
||||
//
|
||||
// Copyright (c) 2013 Roman Efimov (https://github.com/romaonthego)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
//
|
||||
|
||||
#import "RELengthValidator.h"
|
||||
#import "NSError+REValidation.h"
|
||||
|
||||
@implementation RELengthValidator
|
||||
|
||||
+ (NSString *)name
|
||||
{
|
||||
return @"length";
|
||||
}
|
||||
|
||||
+ (NSDictionary *)parseParameterString:(NSString *)string
|
||||
{
|
||||
NSError *error = NULL;
|
||||
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"(\\d+)" options:0 error:&error];
|
||||
NSArray *matches = [regex matchesInString:string options:0 range:NSMakeRange(0, string.length)];
|
||||
NSMutableArray *results = [NSMutableArray array];
|
||||
for (NSTextCheckingResult *matchResult in matches) {
|
||||
NSString *match = [string substringWithRange:[matchResult range]];
|
||||
[results addObject:match];
|
||||
}
|
||||
if (results.count == 2) {
|
||||
return @{ @"min": results[0], @"max": results[1]};
|
||||
}
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
+ (NSError *)validateObject:(NSString *)object variableName:(NSString *)name parameters:(NSDictionary *)parameters
|
||||
{
|
||||
NSUInteger minimumValue = [parameters[@"min"] integerValue];
|
||||
NSUInteger maximumValue = [parameters[@"max"] integerValue];
|
||||
|
||||
if (object.length < minimumValue && minimumValue > 0)
|
||||
return [NSError re_validationErrorForDomain:@"com.REValidation.minimumLength", name, minimumValue];
|
||||
|
||||
if (object.length > maximumValue && maximumValue > 0)
|
||||
return [NSError re_validationErrorForDomain:@"com.REValidation.maximumLength", name, maximumValue];
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
@end
|
||||
30
RETableViewManagerExample/Pods/REValidation/REValidation/Validators/REPresenceValidator.h
generated
Normal file
30
RETableViewManagerExample/Pods/REValidation/REValidation/Validators/REPresenceValidator.h
generated
Normal file
@@ -0,0 +1,30 @@
|
||||
//
|
||||
// REPresenceValidator.h
|
||||
// REValidation
|
||||
//
|
||||
// Copyright (c) 2013 Roman Efimov (https://github.com/romaonthego)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
//
|
||||
|
||||
#import "REValidator.h"
|
||||
|
||||
@interface REPresenceValidator : REValidator
|
||||
|
||||
@end
|
||||
44
RETableViewManagerExample/Pods/REValidation/REValidation/Validators/REPresenceValidator.m
generated
Normal file
44
RETableViewManagerExample/Pods/REValidation/REValidation/Validators/REPresenceValidator.m
generated
Normal file
@@ -0,0 +1,44 @@
|
||||
//
|
||||
// REPresenceValidator.m
|
||||
// REValidation
|
||||
//
|
||||
// Copyright (c) 2013 Roman Efimov (https://github.com/romaonthego)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
//
|
||||
|
||||
#import "REPresenceValidator.h"
|
||||
#import "NSError+REValidation.h"
|
||||
|
||||
@implementation REPresenceValidator
|
||||
|
||||
+ (NSString *)name
|
||||
{
|
||||
return @"presence";
|
||||
}
|
||||
|
||||
+ (NSError *)validateObject:(NSString *)object variableName:(NSString *)name parameters:(NSDictionary *)parameters
|
||||
{
|
||||
if (![object isKindOfClass:[NSString class]] || object.length == 0)
|
||||
return [NSError re_validationErrorForDomain:@"com.REValidation.presence", name];
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
@end
|
||||
30
RETableViewManagerExample/Pods/REValidation/REValidation/Validators/REURLValidator.h
generated
Normal file
30
RETableViewManagerExample/Pods/REValidation/REValidation/Validators/REURLValidator.h
generated
Normal file
@@ -0,0 +1,30 @@
|
||||
//
|
||||
// REURLValidator.h
|
||||
// REValidation
|
||||
//
|
||||
// Copyright (c) 2013 Roman Efimov (https://github.com/romaonthego)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
//
|
||||
|
||||
#import "REValidator.h"
|
||||
|
||||
@interface REURLValidator : REValidator
|
||||
|
||||
@end
|
||||
51
RETableViewManagerExample/Pods/REValidation/REValidation/Validators/REURLValidator.m
generated
Normal file
51
RETableViewManagerExample/Pods/REValidation/REValidation/Validators/REURLValidator.m
generated
Normal file
@@ -0,0 +1,51 @@
|
||||
//
|
||||
// REURLValidator.m
|
||||
// REValidation
|
||||
//
|
||||
// Copyright (c) 2013 Roman Efimov (https://github.com/romaonthego)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
//
|
||||
|
||||
#import "REURLValidator.h"
|
||||
#import "REValidation.h"
|
||||
|
||||
@implementation REURLValidator
|
||||
|
||||
+ (NSString *)name
|
||||
{
|
||||
return @"url";
|
||||
}
|
||||
|
||||
+ (NSError *)validateObject:(NSString *)object variableName:(NSString *)name parameters:(NSDictionary *)parameters
|
||||
{
|
||||
NSString *string = object ? object : @"";
|
||||
if (string.length == 0)
|
||||
return nil;
|
||||
|
||||
NSError *error = NULL;
|
||||
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"^(?i)(?:(?:https?|ftp):\\/\\/)?(?:\\S+(?::\\S*)?@)?(?:(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)*(?:\\.(?:[a-z\\u00a1-\\uffff]{2,})))(?::\\d{2,5})?(?:\\/[^\\s]*)?$" options:NSRegularExpressionCaseInsensitive error:&error];
|
||||
NSTextCheckingResult *match = [regex firstMatchInString:string options:0 range:NSMakeRange(0, string.length)];
|
||||
if (!match)
|
||||
return [NSError re_validationErrorForDomain:@"com.REValidation.url", name];
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user