• Stars
    star
    593
  • Rank 75,443 (Top 2 %)
  • Language
    Objective-C
  • License
    Other
  • Created almost 13 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Form validation framework for iOS.

![Import framework screen](https://github.com/ustwo/US2FormValidator/raw/master/Documentation/Images/Form Validator Sample Preview.png)

ustwo™ iOS Form Validator

Build Status

This framework allows you to validate inputs of text fields and text views in a convenient way.

Features

  • Simply use US2ValidatorTextField instead of UITextField (US2ValidatorTextView instead of UITextView)
  • Know what went wrong and where
  • Create own conditions using regular expressions for example
  • Create own validators which contain a collection of conditions

Installation

Clone the project

Clone the project from the link above.

Import the framework project into your project

![Import framework screen](https://github.com/ustwo/US2FormValidator/raw/master/Documentation/Images/Import Framework.png)

Set target dependencies

![Target dependencies screen](https://github.com/ustwo/US2FormValidator/raw/master/Documentation/Images/Target Dependencies.png)

Add US2Localizable.strings to your projects Copy Bundle Resources

![Target dependencies screen](https://github.com/ustwo/US2FormValidator/raw/master/Documentation/Images/Bundle Resources.png)

Installation using CocoaPods

How to use CocoaPods? Go to: https://github.com/CocoaPods/CocoaPods

Add the following line to your pod file:

pod 'US2FormValidator', '~> 1.1.2'

How-To

Add a condition to validator

US2Validator *validator = [[US2Validator alloc] init];

US2ConditionAlphabetic *condition = [[US2ConditionAlphabetic alloc] init];
[validator addCondition:condition];
[condition release];

US2ConditionCollection *conditionCollection1 = [validator checkConditions:@"HelloWorld"];
US2ConditionCollection *conditionCollection2 = [validator checkConditions:@"Hello World 123"];

BOOL isValid = conditionCollection1 == nil;                                                  // isValid == YES
isValid = conditionCollection2 == nil;                                                       // isValid == NO

// What went wrong?
NSLog(@"conditionCollection2: %@", conditionCollection2);

Add a validation text field

US2ValidatorTextField *firstNameTextField  = [[US2ValidatorTextField alloc] init];
firstNameTextField.validator               = [[[MyProjectValidatorName alloc] init] autorelease];
firstNameTextField.shouldAllowViolation    = YES;
firstNameTextField.validateOnFocusLossOnly = YES;
firstNameTextField.placeholder             = @"Enter first name";
firstNameTextField.validatorUIDelegate     = self;
[_textUICollection addObject:firstNameTextField];
[firstNameTextField release];

Create own condition

Create the interface.

#import <Foundation/Foundation.h>
#import "US2Condition.h"


@interface MyProjectConditionName : US2Condition

@end

Create the implementation.

#import "MyProjectConditionName.h"


@implementation MyProjectConditionName

- (BOOL)check:(NSString *)string
{
	if (nil == string)
		string = [NSString string];
	
	self.regexString = @"[a-zA-Z .-]";
	
	return [super check:string];
}


#pragma mark - Allow violation

- (BOOL)shouldAllowViolation
{
	return YES;
}


#pragma mark - Localization

- (NSString *)localizedViolationString
{
	return @"Not a valid name";
}


@end

Create own validator

Create the interface.

#import <Foundation/Foundation.h>
#import "US2Validator.h"


#pragma mark - Validator interface

@interface MyProjectValidatorName : US2Validator
{
}


@end

Create the implementation.

#import "MyProjectValidatorName.h"
#import "MyProjectConditionName.h"
#import "US2ConditionRange.h"


@implementation MyProjectValidatorName


#pragma mark - Initialization

- (id)init
{
	self = [super init];
	if (self)
	{
		[self addCondition:[[[MyProjectConditionName alloc] init] autorelease]];
		
		US2ConditionRange *rangeCondition   = [[[US2ConditionRange alloc] init] autorelease];
		rangeCondition.range                = NSMakeRange(2, UINT16_MAX);
		rangeCondition.shouldAllowViolation = YES;
		
		[self addCondition:rangeCondition];
	}
	
	return self;
}


@end

githalytics.com alpha

More Repositories

1

ustwo.com-frontend

The New & Improved ustwo Website
JavaScript
1,818
star
2

formvalidator-swift

A framework to validate inputs of text fields and text views in a convenient way.
Swift
495
star
3

mastermind

Man in the middle testing
Python
385
star
4

clockwise

Watch face framework for Android Wear developed by ustwo
Java
345
star
5

videoplayback-ios

Swift AVPlayer wrapper using the VIPER architecture. Currently a work in progress
Swift
218
star
6

autocluster

The code base around the cluster prototypes.
JavaScript
101
star
7

ReplayKitUnityBridge

A bridge created from iOS to Unity - exposing the Cocoa ReplayKit API. It allows you to record the screen, set a limited time for the screen to be recorded, and receive a file of the recorded session
ASP
61
star
8

vip-demo-swift

Swift sample app demonstrating VIP architecture for iOS.
Swift
49
star
9

android-boilerplate

Android Boilerplate à la ustwo
Java
42
star
10

docker-browser-sync

Docker image for BrowserSync
JavaScript
39
star
11

vip-templates-swift

Xcode templates based on https://clean-swift.com for generating Swift source code in View Interactor Presenter architecture.
Shell
32
star
12

bdd-crossplatform-apps

An ustwo guide about one way to BDD cross platform applications.
Ruby
27
star
13

clockwise-samples

Sample watch faces
Java
24
star
14

GL-2D-watchface

A light-weight library to manage and render Bitmaps in OpenGL on a watch face.
Java
20
star
15

objective-c-style-guide

The ustwo Objective-C style guide
20
star
16

US2MapperKit

JSON driven object mapper developed by ustwo
Swift
17
star
17

midi-to-philips-hue

This is a proof of concept of a set of Philips Hue lights controlled by a Behringer BCD300 MIDI controller
Ruby
16
star
18

android-coding-standards

Android Coding Standards
16
star
19

daydream-experiment

Google Daydream Experiment
C#
15
star
20

recipe-book

ustwobies love food, so they Open Source their recipes, as any sane geek would do.
15
star
21

docker-node-boilerplate

⚠️ No longer maintained ⚠️
JavaScript
10
star
22

brunel

A demonstration of organisation for an app that runs on both iOS and tvOS platforms using a unified code base. ⚠️ No longer maintained ⚠️
Swift
9
star
23

docker-sauce-connect

Builds a Sauce Labs Connect image
Makefile
9
star
24

photoshop-contrast-checker

JavaScript
8
star
25

baseviewcontroller-swift

An organizational tool for writing custom view controllers using UIKit.
Ruby
8
star
26

branded-interactions

JavaScript
7
star
27

react-native-experiment

React Native experiment for mapping of content
JavaScript
7
star
28

scout

Scout discovers apps installed on an iOS device utilising the URL scheme feature.
Objective-C
7
star
29

ibeacon-demo

Objective-C
6
star
30

US2KeyboardType

Objective-C
5
star
31

ustwoadventure

Front-end code for the Adventure website
JavaScript
5
star
32

autolayout-helper-ios

UIView helper to easily create common Auto Layout Constraints for iOS
Objective-C
4
star
33

image-color-swift

Swift
4
star
34

toolbar-keyboard-ios

UIToolbar extension to create toolbars useful for keyboards or pickers for iOS
Objective-C
4
star
35

mockingbird

A demonstration of using the Swift Package Manager and writing Swift code to run on both Linux and macOS.
Swift
3
star
36

array-remove-swift

Swift
2
star
37

xcode-snippets

Xcode Snippets
2
star
38

mongolabkit-swift

MongoLabKit is a REST client API for iOS, tvOS and watchOS written to make REST calls to a MongoLab database.
Swift
2
star
39

github-scanner

A commandline tool for scanning GitHub repositories. ⚠️ No longer maintained ⚠️
Swift
2
star
40

bench-xr-social-experiments

C#
1
star
41

ustwo-swiftui-bindings-example

Swift
1
star
42

google-docs-scripts

A collection of Google docs scripts
JavaScript
1
star
43

UIColor-US2Colors

UIColor+US2Colors category
Objective-C
1
star
44

homebrew-tools

Collection of tools ustwo development might need
Ruby
1
star
45

ios-swift-dictionaries-sample

Sample code from "Reading from a Dictionary in Swift" blog post.
Objective-C
1
star
46

docker-ansible

DEPRECATED
Makefile
1
star
47

pink-workshop-22

JavaScript
1
star
48

docker-nodejs

DEPRECATED
Makefile
1
star
49

baseview-swift

UIView subclass to abstract Base functionality for iOS
Swift
1
star
50

github-issues

A command line interface to fetch Github Issues ⚠️ No longer maintained ⚠️
Rust
1
star
51

engineering-blog

usTwo Engineering
SCSS
1
star