"Design is a plan for arranging elements in such a way as best to accomplish a particular purpose" — Charles Eames

When writing our own program, you’ll often want to add some new method to an existing class. You can always add a subclass to an existing class if you want to add some more method to it. But there are limitations to that, not every time subclassing is convenient enough for people to subclass. For example, you want to add an email address validator method to NSString, but NSString is the top of the hierarchy of the class cluster, which makes it difficult to subclass.

Note: A class cluster is an architecture that groups a number of private, concrete subclasses under a public, abstract superclass. The grouping of classes in this way provides a simplified interface to the user, who sees only the publicly visible architecture. Read more about class clusters here: http://developer.apple.com/library/mac/#documentation/General/
Conceptual/DevPedia-CocoaCore/ClassCluster.html

But because of the difficulties, Objective-C has this brilliant mechanism that will let you add a new method to an existing class without any difficulties. The term for is called Categories.

Creating a Category Method
A category is a way to add a new method to an existing class even if you don’t have the source code for it. Let’s say you want to add an NSString method that …

UPPEValidator is a simple PHP class that will help validate email addresses, URLs, passwords, and phone numbers. You can download the script in the link listed below.
UPPEValidator Download Link

Gist

Sample Usage :

$validator = new UPPEValidator();
$string = ’09-088-909-8890′; // You can also use dots ( . ) instead of hyphens ( – )

if( $validator->is_phone( $string ) === true )
{
echo ‘success’;
}
else
{
echo ‘failed’;
}

Functions :

is_email()
is_url_string()
is_password()
is_phone()

Pages

Copyright © 2010 - 2013 Studio Villegas. All Rights Reserved.