Class o2.Validation
static
class
o2.Validation
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');
Checks whether the object is an arguments object.
Usage example:
var isArguments = o2.Validation.isArguments(arguments);
Checks whether the object is an Array.
Usage example:
var isArray = o2.Validation.isArray([]);
Checks whether the object is a Boolean.
Usage example:
var isBoolean = o2.Validation.isBoolean(false);
Checks whether the object is a Date.
Usage example:
var isDate = o2.Validation.isDate((ew Date());
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');
Usage example:
var isFunction = o2.Validation.isFunction(fnTest);
Checks whether the object is a Function.
Usage example:
var isNaN = o2.Validation.isNaN('lorem');
Checks whether the given parameter is NaN.
Usage example:
var isNull = o2.Validation.isNull(null);
Checks whether the given parameter is null.
Usage example:
var isNumber = o2.Validation.isNumber(42);
Checks whether the object is a Number.
Usage example:
var isNumeric = o2.Validation.isNumeric('4.2');
Checks whether the given parameter is a numeric entity.
Usage example:
var isObject = o2.Validation.isObject({});
Checks whether the object is an Object({}).
Usage example:
var isRegExp = o2.Validation.isRegExp(/test/ig);
Checks whether the object is a RegExp.
Usage example:
var isString = o2.Validation.isString('lorem');
Checks whether the object is a String.
Usage example:
var isUndefined = o2.Validation.isUndefined(undefined);
Checks whether the given parameter is undefined.
Checks whether the given argument is a valid URL address.
Usage example:
var isUrl = o2.Validation.isUrl('http://o2js.com/');
Checks whether the given argument consists of only whitespace characters.
Usage example:
var isWhitespace = o2.Validation.isWhitespace(' \t\r\n \n ');
Function Details
function is
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');
obj
- the object to check type against.
type
- the type to compare. 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);
obj
- the object to test. 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([]);
obj
- the object to test. 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);
obj
- the object to test. 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());
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. 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');
mail
- the e-mail address to test. 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.
obj
- the object to test. 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.
obj
- the Object to test. 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.
obj
- the Object to test. 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.
obj
- the object to test. 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.
obj
- the Object to test. 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({}).
obj
- the object to test. 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.
obj
- the object to test. 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.
obj
- the object to test. function isUndefined
static
isUndefined(Object
obj)
Usage example:
var isUndefined = o2.Validation.isUndefined(undefined);
Checks whether the given parameter is undefined.
obj
- the Object to test. 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/');
url
- the address to check. 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 ');
text
- the text to check. 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.
obj
- the Object to test. true if the item is a window,
false otherwise.
A simple class for validating various kinds of objects.