Class: Validation

Validation()

new Validation()

Create a new Validation object. All methods on this class are static.

Methods

(static) validateBoolean(bool, options, thisNameopt)

Validate a boolean

Parameters:
Name Type Attributes Default Description
bool Boolean

The boolean to be validated

options Object
Properties
Name Type Attributes Default Description
required Boolean <optional>
true
thisName String <optional>
"validateBoolean"

Set to have better error messaging, ie error.message = "UserModel hasName is required."

Throws:
Example
Validation.validateBoolean(true);

(static) validateEmail(email, options, thisNameopt)

Validate an email address

Parameters:
Name Type Attributes Default Description
email String

The email address to be validated

options Object
Properties
Name Type Attributes Default Description
required Boolean <optional>
true
thisName String <optional>
"validateUrl"

Set to have better error messaging, ie error.message = "UserModel imageUrl is required."

Throws:
Example
Validation.validateEmail("dan@example.com");

(static) validateInstanceOf(object, constructor, options, thisNameopt)

Validate an object is an instance of another object

Parameters:
Name Type Attributes Default Description
object Object

The object to be validated

constructor Object

The constructor to be validated against

options Object
Properties
Name Type Attributes Default Description
required Boolean <optional>
true
thisName String <optional>
"validateInstanceOf"

Set to have better error messaging, ie error.message = "UserModel emailModel is required."

Throws:
Example
Validation.validateInstanceOf(userModel, UserModel);

(static) validateNumber(number, options, thisNameopt)

Validate a number

Parameters:
Name Type Attributes Default Description
number Number

The number to be validated

options Object
Properties
Name Type Attributes Default Description
required Boolean <optional>
true

If true, will check the string for undefined, null, and empty

minValue Number <optional>
Number.MIN_SAFE_INTEGER

If set will check the number for a minimum value.

maxValue Number <optional>
Number.MAX_SAFE_INTEGER

If set will check the number for a maximum value.

name String <optional>

Set to have better error messaging, ie error.message = "UserModel count is required."

thisName String <optional>
"validateNumber"

Set to have better error messaging, ie error.message = "UserModel count is required."

Throws:
Example
Validation.validateNumber(5);

(static) validateString(string, options, thisNameopt)

Validate a string

Parameters:
Name Type Attributes Default Description
string String

The string to be validated

options Object
Properties
Name Type Attributes Default Description
required Boolean <optional>
true

If true, will check the string for undefined, null, and empty

minLength Number <optional>

If set will check the string for a minimum length of characters.

maxLength Number <optional>
100000

If set will check the string for a maximum length of characters.

name String <optional>

Set to have better error messaging, ie error.message = "UserModel id is required."

thisName String <optional>
"validateString"

Set to have better error messaging, ie error.message = "UserModel id is required."

Throws:
Example
Validation.validateString("foo");

(static) validateUrl(url, options, thisNameopt)

Validate a url

Parameters:
Name Type Attributes Default Description
url String

The url to be validated

options Object
Properties
Name Type Attributes Default Description
required Boolean <optional>
true
protocols Array.<String> <optional>
[http:, https:]

By default a url must have an http: or https: protocol. Pass in a list of protocols to override this.

name String <optional>

Set to have better error messaging, ie error.message = "UserModel imageUrl is required."

thisName String <optional>
"validateUrl"

Set to have better error messaging, ie error.message = "UserModel imageUrl is required."

Throws:
Example
Validation.validateUrl("https://example.com");