Class o2.Validation


static class o2.Validation

A simple class for validating various kinds of objects.

Defined in validation.core

Function Summary
private is (Object obj, String type)

Returns the type information of the given object.

The type can be any of the following:

Array, Boolean, Date, Error, Function, JSON, Math, Number, Object, RegExp, String, Arguments.

Usage example:

 var obj = {lorem : 'dolor'};
 var isObject = o2.Validation.is(obj, 'Object');
 
static isArguments (Object obj)

Checks whether the object is an arguments object.

Usage example:

 var isArguments = o2.Validation.isArguments(arguments);
 
static isArray (Object obj)

Checks whether the object is an Array.

Usage example:

 var isArray = o2.Validation.isArray([]);
 
static isBoolean (Object obj)

Checks whether the object is a Boolean.

Usage example:

 var isBoolean = o2.Validation.isBoolean(false);
 
static isDate (Arguments varargin)

Checks whether the object is a Date.

Usage example:

 var isDate = o2.Validation.isDate((ew Date());
 
static isEmail (String mail)

Did you know that Abc\@def@example.com, and customer/department=shipping@example.com are all valid e-mails?

There is no good (and realistic) regular expression to match an e-mail address.

The grammar ( http://www.ietf.org/rfc/rfc5322.txt ) is too complicated for that.

This method matches e-mail addresses, while giving some false-positives.

The correct action to validate an e-mail address is to validate by trying (i.e. try sending an account activation e-mail to a newly registered user, for example.).

Usage example:

 var isEmail = o2.Validation.isEmail('volkan@o2js.com');
 
static isFunction (Object obj)

Usage example:

 var isFunction = o2.Validation.isFunction(fnTest);
 

Checks whether the object is a Function.

static isNaN (Object obj)

Usage example:

 var isNaN = o2.Validation.isNaN('lorem');
 

Checks whether the given parameter is NaN.

static isNull (Object obj)

Usage example:

 var isNull = o2.Validation.isNull(null);
 

Checks whether the given parameter is null.

static isNumber (Object obj)

Usage example:

 var isNumber = o2.Validation.isNumber(42);
 

Checks whether the object is a Number.

static isNumeric (Object obj)

Usage example:

 var isNumeric = o2.Validation.isNumeric('4.2');
 

Checks whether the given parameter is a numeric entity.

static isObject (Object obj)

Usage example:

 var isObject = o2.Validation.isObject({});
 

Checks whether the object is an Object({}).

static isRegExp (Object obj)

Usage example:

 var isRegExp = o2.Validation.isRegExp(/test/ig);
 

Checks whether the object is a RegExp.

static isString (Object obj)

Usage example:

 var isString = o2.Validation.isString('lorem');
 

Checks whether the object is a String.

static isUndefined (Object obj)

Usage example:

 var isUndefined = o2.Validation.isUndefined(undefined);
 

Checks whether the given parameter is undefined.

static isUrl (String url)

Checks whether the given argument is a valid URL address.

Usage example:

 var isUrl = o2.Validation.isUrl('http://o2js.com/');
 
static isWhitespace (String text)

Checks whether the given argument consists of only whitespace characters.

Usage example:

 var isWhitespace = o2.Validation.isWhitespace('  \t\r\n   \n  ');
 
static isWindow (Object obj)

Usage example:

 var isWindow = o2.Validation.isWindow(window);
 

Checks whether the given parameter is a window object.

Function Details

function is

private is(Object obj, String type)

Returns the type information of the given object.

The type can be any of the following:

Array, Boolean, Date, Error, Function, JSON, Math, Number, Object, RegExp, String, Arguments.

Usage example:

 var obj = {lorem : 'dolor'};
 var isObject = o2.Validation.is(obj, 'Object');
 
Parameters:
obj - the object to check type against.
type - the type to compare.
Returns:
true if the object's type matches the type parameter, false otherwise.

function isArguments

static isArguments(Object obj)

Checks whether the object is an arguments object.

Usage example:

 var isArguments = o2.Validation.isArguments(arguments);
 
Parameters:
obj - the object to test.
Returns:
true if obj is an arguments object, false otherwise.

function isArray

static isArray(Object obj)

Checks whether the object is an Array.

Usage example:

 var isArray = o2.Validation.isArray([]);
 
Parameters:
obj - the object to test.
Returns:
true if obj is an Array, false otherwise.

function isBoolean

static isBoolean(Object obj)

Checks whether the object is a Boolean.

Usage example:

 var isBoolean = o2.Validation.isBoolean(false);
 
Parameters:
obj - the object to test.
Returns:
true if obj is a Boolean, false otherwise.

function isDate

static isDate(Arguments varargin)

Checks whether the object is a Date.

Usage example:

 var isDate = o2.Validation.isDate((ew Date());
 
Parameters:
varargin - if a single argument is given it checks whether it identifies a Date object. Otherwise the function takes three parameters (year, month, date) and cheks whether they denote a valid Date.
Returns:
true if obj is a Date, false otherwise.

function isEmail

static isEmail(String mail)

Did you know that Abc\@def@example.com, and customer/department=shipping@example.com are all valid e-mails?

There is no good (and realistic) regular expression to match an e-mail address.

The grammar ( http://www.ietf.org/rfc/rfc5322.txt ) is too complicated for that.

This method matches e-mail addresses, while giving some false-positives.

The correct action to validate an e-mail address is to validate by trying (i.e. try sending an account activation e-mail to a newly registered user, for example.).

Usage example:

 var isEmail = o2.Validation.isEmail('volkan@o2js.com');
 
Parameters:
mail - the e-mail address to test.
Returns:
true if the e-mail address is a potentially valid e-mail, false otherwise.

function isFunction

static isFunction(Object obj)

Usage example:

 var isFunction = o2.Validation.isFunction(fnTest);
 

Checks whether the object is a Function.

Parameters:
obj - the object to test.
Returns:
true if obj is a Function, false otherwise.

function isNaN

static isNaN(Object obj)

Usage example:

 var isNaN = o2.Validation.isNaN('lorem');
 

Checks whether the given parameter is NaN.

Parameters:
obj - the Object to test.
Returns:
true if the item is NaN, false otherwise.

function isNull

static isNull(Object obj)

Usage example:

 var isNull = o2.Validation.isNull(null);
 

Checks whether the given parameter is null.

Parameters:
obj - the Object to test.
Returns:
true if the item is null, false otherwise.

function isNumber

static isNumber(Object obj)

Usage example:

 var isNumber = o2.Validation.isNumber(42);
 

Checks whether the object is a Number.

Parameters:
obj - the object to test.
Returns:
true if obj is a Number, false otherwise.

function isNumeric

static isNumeric(Object obj)

Usage example:

 var isNumeric = o2.Validation.isNumeric('4.2');
 

Checks whether the given parameter is a numeric entity.

Parameters:
obj - the Object to test.
Returns:
true if the item is a numeric entity, false otherwise.

function isObject

static isObject(Object obj)

Usage example:

 var isObject = o2.Validation.isObject({});
 

Checks whether the object is an Object({}).

Parameters:
obj - the object to test.
Returns:
true if obj is an Object ({}), false otherwise.

function isRegExp

static isRegExp(Object obj)

Usage example:

 var isRegExp = o2.Validation.isRegExp(/test/ig);
 

Checks whether the object is a RegExp.

Parameters:
obj - the object to test.
Returns:
true if obj is a RegExp, false otherwise.

function isString

static isString(Object obj)

Usage example:

 var isString = o2.Validation.isString('lorem');
 

Checks whether the object is a String.

Parameters:
obj - the object to test.
Returns:
true if obj is a String, false otherwise.

function isUndefined

static isUndefined(Object obj)

Usage example:

 var isUndefined = o2.Validation.isUndefined(undefined);
 

Checks whether the given parameter is undefined.

Parameters:
obj - the Object to test.
Returns:
true if the item is undefined, false otherwise.

function isUrl

static isUrl(String url)

Checks whether the given argument is a valid URL address.

Usage example:

 var isUrl = o2.Validation.isUrl('http://o2js.com/');
 
Parameters:
url - the address to check.
Returns:
true if the address is a valid URL, false otherwise.

function isWhitespace

static isWhitespace(String text)

Checks whether the given argument consists of only whitespace characters.

Usage example:

 var isWhitespace = o2.Validation.isWhitespace('  \t\r\n   \n  ');
 
Parameters:
text - the text to check.
Returns:
true if the argument consists of only whitespace characters, false otherwise.

function isWindow

static isWindow(Object obj)

Usage example:

 var isWindow = o2.Validation.isWindow(window);
 

Checks whether the given parameter is a window object.

Parameters:
obj - the Object to test.
Returns:
true if the item is a window, false otherwise.