Code Monkey home page Code Monkey logo

vforvalidation's Introduction

V For Validation

Imagine the next scenario: You have an awesome app, probably you use a form for register users, or maybe you need check when one field is valid or not... I'm pretty sure that you use a simple way to check each textField, switch... V For Validation try to help you for do it possible with an easy way.

How it works

IMPORTANT TO KNOW:

Validate != Check
  • Validate executes validation and validated block.
  • Check only executes validation block.

VFV have 2 parts:

  • VFValidationManager.h: Contains all validations and It's responsible to check and validate.
  • VFValidation.h: Check what needs validate and what happens when did it.
  • VFRegularExpression.h: Create a regular expression and validate if string was valid.

Installation

Manual

Drag and drop or copy Source Folder into your project.

##Pod

pod 'VForValidation'

##Getting started

  1. Import library
#import "VForValidation.h"
  1. Create Manager
///@interface
@property (nonatomic, strong) VFValidationManager *validationManager;

///-(void)viewDidLoad
self.validationManager = [[VFValidationManager alloc] init];
  1. Creates validation
  VFValidation *validation = [[VFValidation alloc] initWithValidationBlock:^BOOL{
      return 1 != 2;
  } validatedBlock:^(NSString *key, BOOL validated) {
      if (validated) NSLog(@"True");
      else NSLog(@"False");
  } key:@"key"];
  ```
  or
  
  ```Objective-C
  VFValidation *validation = [[VFValidation alloc] initWithValidationBlock:^BOOL{
      VFRegularExpression *regex = [[VFRegularExpression alloc]   
              initWithRegularExpression:@"^[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}$" 
                      stringToValidate:@"[email protected]"];
      return [regex validate];
  } validatedBlock:^(NSString *key, BOOL validated) {
      if (validated) NSLog(@"True");
      else NSLog(@"False");
  } key:@"key"];
  ```
4. Add Validation
```Objective-C
[self.validationManager addValidation:validation]; 
  1. When you want, VALIDATE!
[self.validationManager validate];

##API

  • VFValidationManager.h
 ///Constructors
  -(instancetype)initWithValidations:(NSArray *)validations;
  
   ///Adders
  -(void)addValidation:(VFValidation *)validation;
  -(void)addValidations:(NSArray *)validations;
  
  ///Modifiers
  -(void)updateValidation:(VFValidation *)validation;
  
  ///Getters
  -(VFValidation *)validationByKey:(NSString *)key;
  -(NSArray *)validations;
  
  ///Validate and Check
  -(void)validateByKey:(NSString *)key;
  -(void)checkIfAllWasValidWithCompletion:(ValidatedWithoutKey)validated;
  -(void)validateAndCheckIfAllWasValidWithCompletion:(ValidatedWithoutKey)validated;
  • VFValidation.h
///Constructors
  -(instancetype)initWithValidationBlock:(ValidationBlock)validation
                          validatedBlock:(ValidatedBlock)validated;
  -(instancetype)initWithValidationBlock:(ValidationBlock)validation
                          validatedBlock:(ValidatedBlock)validated
                                     key:(NSString *)key;
///Setters
  -(void)setValidationBlock:(ValidationBlock)validationBlock;
  -(void)setValidatedBlock:(ValidatedBlock)validatedBlock;
  -(void)setValidationBlock:(ValidationBlock)validationBlock
             validatedBlock:(ValidatedBlock)validatedBlock;
  -(void)setKey:(NSString *)key;
  
///Validate and Check
  -(void)validate;
  -(void)checkValidationWithCompletion:(ValidatedWithouKey)validated;
  -(void)validateAndCheckWithCompletion:(ValidatedWithouKey)validated;
  • VFRegularExpression.h
  ///Constructors
  - (instancetype)initWithRegularExpression:(NSString *)regex
                       stringToValidate:(NSString *)stringToValidate;
                       
  ///Public API
  - (BOOL)validate;

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b VFV-new-feature
  3. Commit your changes: git commit -am 'Add new feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request ๐Ÿ‘Œ

Credits

License

VFV is available under the MIT license.

vforvalidation's People

Contributors

joanmolinas avatar

Stargazers

MohsinAli avatar

Watchers

MohsinAli avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.