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
|
||||||||||||
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
|
||||||||||||
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
|
||||||||||||
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
|
|||||||||||||||||||||||||||
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
|
|||||||||||||||||||||||||||
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
|
||||||||||||||||||||||
thisName |
String |
<optional> |
"validateUrl" | Set to have better error messaging, ie error.message = "UserModel imageUrl is required." |
Throws:
Example
Validation.validateUrl("https://example.com");