String
Path:
/src/type/string.coffee
compiled to/lib/type/string.js
This will test for strings and have lots of sanitize and optimization filters and also different check settings to use.
Sanitize options allowed:
makeString
-Boolean
convert objects to string, firstallowControls
-Boolean
keep control characters in string instead of stripping them (but keep \r\n)stripTags
-Boolean
remove all html tagslowerCase
-Boolean|String
set totrue
orfirst
upperCase
-Boolean|String
set totrue
orfirst
replace
-Array
replacements: string (only single replacement) or regular expressions and replacements as inner arraytrim
-Boolean
strip whitespace from the beginning and endcrop
-Integer
crop text after number of characters
Check options:
optional
-Boolean
the value must not be present (will return null)minLength
-Integer
minimum text length in charactersmaxLength
-Integer
maximum text length in charactersvalues
-Array|Object|String
array of possible values (complete text)startsWith
-String
start of textendsWith
-String
end of textmatch
-String|RegExp
string or regular expression which have to be matched (or list of expressions)matchNot
-String|RegExp
string or regular expression which is not allowed to match (or list of expressions)
Example:
CoffeeScript Code validator.check
name: 'test' # name to be displayed in errors (optional)
value: input # value to check
schema: # definition of checks
type: 'string'
lowerCase: true
upperCase: 'first'
values: ['One', 'Two', 'Three']
, (err, result) ->
# do something
Character Case
Instead of setting to lowerCase
or upperCase
you can also set both. If you
set one to true
and the other to first
you can make all lowercase but first
character uppercase or the other way.
Schema Specification
String is a string schema definition.
An object with the following keys allowed: makeString
, allowControls
, stripTags
, lowerCase
, upperCase
, replace
, trim
, crop
, minLength
, maxLength
, values
, startsWith
, endsWith
, match
, matchNot
, title
, description
, key
, type
, optional
, default
. The following entries have a specific format:
makeString
-
Make String is a switch to transform objects into string using the
toString()
method.A boolean value, which will be true for ‘true’, ‘1’, ‘on’, ‘yes’, ‘+’, 1, true and will be considered as false for ‘false’, ‘0’, ‘off’, ‘no’, ‘-’, 0, false. It’s optional.
allowControls
-
Allow Controls are a flag defining that controls are allowed if set to
true
.A boolean value, which will be true for ‘true’, ‘1’, ‘on’, ‘yes’, ‘+’, 1, true and will be considered as false for ‘false’, ‘0’, ‘off’, ‘no’, ‘-’, 0, false. It’s optional.
stripTags
-
Strip Tags are a flag defining if all MTML tags should be removed.
A boolean value, which will be true for ‘true’, ‘1’, ‘on’, ‘yes’, ‘+’, 1, true and will be considered as false for ‘false’, ‘0’, ‘off’, ‘no’, ‘-’, 0, false. It’s optional.
lowerCase
-
Lower Case is the flag to transform first or all characters to lower case.
It has to be one of the following types (optional):
-
Lower Case All is the flag to transform all characters to lower case if set to
true
.A boolean value, which will be true for ‘true’, ‘1’, ‘on’, ‘yes’, ‘+’, 1, true and will be considered as false for ‘false’, ‘0’, ‘off’, ‘no’, ‘-’, 0, false.
-
Lower Case First is a flag if set to
first
it will transform the first character to lower case.A text entry in which all control characters will be removed. Only the values: ‘first’ are allowed.
-
upperCase
-
Upper Case is the flag to transform first or all characters to upper case.
It has to be one of the following types (optional):
-
Upper Case All is the flag to transform all characters to upper case if set to
true
.A boolean value, which will be true for ‘true’, ‘1’, ‘on’, ‘yes’, ‘+’, 1, true and will be considered as false for ‘false’, ‘0’, ‘off’, ‘no’, ‘-’, 0, false.
-
Lower Case First is a flag if set to
first
it will transform the first character to upper case.A text entry in which all control characters will be removed. Only the values: ‘first’ are allowed.
-
replace
-
Replacement is a part to be replaced.
It has to be one of the following types (optional):
-
One Replacement is the replacement to be done.
A list. The following entries have a specific format:
-
Multiple Replacements are a list of replacements to be done.
A list. Each entry has to be of type array:
One Replacement is the replacement to be done.
A list. The following entries have a specific format:
-
trim
-
Trim is a flag set to
true
to trim whitespace from the start and end.A boolean value, which will be true for ‘true’, ‘1’, ‘on’, ‘yes’, ‘+’, 1, true and will be considered as false for ‘false’, ‘0’, ‘off’, ‘no’, ‘-’, 0, false. It’s optional.
crop
-
Crop Length is the maximum text length, if greater it will be cut.
An integer value which is optional. The value should be greater than 1.
minLength
-
Minimum Length is the minimum character length of the text.
An integer value which is optional. The value should be greater than 0.
maxLength
-
Maximum Length is the maximum character length of the text.
An integer value which is optional. The value should be greater than <<
>>. values
-
Value List is the list of possible values for this element.
It has to be one of the following types (optional):
-
List of Values are the list of all possible values.
A list. At least 1 elements should be given. Each entry has to be of type string:
Possible Value is a possible value.
A text entry in which all control characters will be removed. - Object of Values are an object from which one of the keys have to be set as value.
An object.
-
Comma List of Values are a comma separated list of possible values.
A text entry in which all control characters will be removed.
-
startsWith
-
Starts With is the text has to start with the given phrase.
A text entry which is optional. All control characters will be removed.
endsWith
-
Ends With is the text has to end with the given phrase.
A text entry which is optional. All control characters will be removed.
match
-
Matches are the text have to match this regular expression.
It has to be one of the following types (optional):
-
List of Matches are a list of matches to succeed.
A list. Each entry has to be of type or:
One Match is the match to succeed.
It has to be one of the following types:
-
RegExp String is the match to be checked for success.
A text entry in which all control characters will be removed.
-
RegExp String is the match to be checked for success.
An object which has to be an instance of class
RegExp
.
-
-
One Match is the match to succeed.
It has to be one of the following types:
-
RegExp String is the match to be checked for success.
A text entry in which all control characters will be removed.
-
RegExp Object is the match to be checked for success.
An object which has to be an instance of class
RegExp
.
-
-
matchNot
-
Negative Matches are the text should not match this regular expression.
It has to be one of the following types (optional):
-
List of Negative Matches are a list of matches which should not succeed.
A list. Each entry has to be of type or:
One Negative Match is the match which should not succeed.
It has to be one of the following types:
-
RegExp String is the match to be checked for failure.
A text entry in which all control characters will be removed.
-
RegExp String is the match to be checked for failure.
An object which has to be an instance of class
RegExp
.
-
-
One Match is the match which should not succeed.
It has to be one of the following types:
-
RegExp String is the match to be checked for failure.
A text entry in which all control characters will be removed.
-
RegExp Object is the match to be checked for failure.
An object which has to be an instance of class
RegExp
.
-
-
title
-
Title is the title used to describe the element.
A text entry which is optional. All control characters will be removed.
description
-
Description is the free description of the element.
A text entry which is optional. All control characters will be removed.
key
-
Binding to Keyname is the mapping to which key names in an object this element belongs.
A valid regular expression which is optional. It has to be one of the following types:
- An object which has to be an instance of class
RegExp
. - A text entry in which all control characters will be removed. The text should match: /^/.?/[gim]$/.
- An object which has to be an instance of class
type
-
Type is the type of element.
A text entry in which all control characters will be removed.
optional
-
Optional is a flag defining if this element is optional.
A boolean value, which will be true for ‘true’, ‘1’, ‘on’, ‘yes’, ‘+’, 1, true and will be considered as false for ‘false’, ‘0’, ‘off’, ‘no’, ‘-’, 0, false. It’s optional.
default
-
Default Value is the default value to use if nothing given.
A text entry which is optional. All control characters will be removed.