Validate form

Usage

The usage is of cource a little diffrent when you are validating forms made in CT, or backend (manully coded). If you are going to do an manuallt implementation then take a look at method list and draw your own conclutions.

Validate form builder fields made in CT

When you are going to create a validatation for a input field created with CT form builder you will have two fields "Method" and "Value". Method is the method name that exists in "\form\valid" framework and value is the selected methods arguments. This means that you only need to take a look at the method list bellow (You can skip the Examples and Start instance, those are for manual usage) copy the method name and if the method has multiple arguments then seperate them as a comma sperated string.

It is possible to add multiple validations to every field.

Example usage (se image bellow)

Find "length" in the method list. In the white box you find "length(int $a, int $b = NULL)".

Set method field in CT

Copy the method name "length" and paste it in the "Method" field in CT.

Set method Value in CT

The method "length" has two arguments "(int $a, int $b = NULL)", int $a means that it must be set as int (integer/number) and int $b = NULL means it's not required becouse it is allready equal "=" to something but if it is set it need to be an int. In most cases we would like to use both arguments becouse it is good practic. So lets set "Value" field in CT to "1,200" which will mean that the user post value must be at least 1 and maxumum 200 characters in length.

If the method does not have any arguments then leave the "Value" field blank in CT.

www

Complete method list

Backend usage
-
@example 1: \form\valid::_val("Lorem ipsum dolor")->length(1);
True becouse the length is more than 1
-
@example 2: \form\valid::_val("Lorem ipsum dolor")->length(1, 200);
True becouse the length is 17
-
@example 3: \form\valid::_val("+46709687050")->phone();
True becouse is phone number
-
@example 4: \form\valid::_val("daniel@creativearmy.se")->allOf(["email", "length" => [1, 120]]);
True becouse value mathes all the validations
-
Start instance
@param ALL $value the input value
@return inst(self)
static _val($value)
Access luhn validation class
@return instance (form\luhnValidation)
luhn()
Set field required (same as @length(1));
@return bool
required()
Validate Swedish personal numbers
@return bool
socialNumber()
Validate Swedish personal numbers
@return bool
personnummer()
Validate Swedish org numbers
@return bool
orgNumber()
Validate creditcardnumbers (THIS needs to be tested)
@return bool
creditcard()
Validate Swedish vat number
@return bool
vatNumber()
Validate email
Loosely check if is email. By loosley I mean it will not check if valid DNS. You can check this manually with the method @dns but in most cases this will not be necessary.
@return bool
email()
Find in string
@param string $match keyword to match agains
@param int|null $pos match start positon if you want
@return bool
findInString(string $match, ?int $pos = NULL)
Alternative "Find in string" @findInString()
strpos(string $match, ?int $pos = NULL)
Check if is phone
@return bool
phone()
Check if is valid ZIP
@param int $a start length
@param int|null $b end length
@return bool
zip(int $a, int $b = NULL)
Value is number
@return bool
number()
Value is number positive 20
@return bool
positive()
Value is number negative -20
@return bool
negative()
Value is minimum float|int value
@return bool
min(float $i)
Value is minimum float|int value (Same as "@min()" but can be used to add another error message)
@return bool
minAlt(float $i)
Value is maximum float|int value
@return bool
max(float $i)
Is value float
@return bool
float()
Is value int
@return bool
int()
Value string length is more than start ($a) or between start ($a) and end ($b)
@param int $a start length
@param int|null $b end length
@return bool
length(int $a, int $b = NULL)
Needs to be filled in, and a valid value (e.g. 0 = false, emtpy = false)
@return bool
isRequired()
Value string length of OTHER field is more than start ($a) or between start ($a) and end ($b)
@param string $key HTTP Post KEY
@param int $a start length
@param int|null $b end length
@return bool
hasLength(string $key, int $a, int $b = NULL)
Value string length is equal to ($a)
@param int $a length
@return bool
equalLength(int $a)
IF value equals to param
@return bool
equal($str)
IF value equals to param
@return bool
notEqual($str)
Is value string
@return bool
string()
Is value is string and character between a-z or A-Z
@return bool
pregMatch($matchStr)
Is value is string and character between a-z or A-Z
@return bool
AtoZ()
Is value is string and character between a-z (LOWERCASE)
@return bool
lowerAtoZ()
Is value is string and character between A-Z (UPPERCASE)
@return bool
upperAtoZ()
Is Hex color code string
@return bool
hex()
Is value array
@return bool
array()
Is value object
@return bool
object()
Is value bool
@return bool
bool()
If value === ([on, off], [yes, no], [1, 0] or [true, false])
@return bool
boolVal()
Is value between two other values (1-10, a-z, 1988-08-01-1988-08-10)
@param int|float|string|date $a 10, a, 1988-08-01
@param int|float|string|date $b 20, z, 1988-08-20
@return bool
between($a, $b)
Check if is a date
@param string $format validate after this date format (default Y-m-d)
@return bool|inst(dateTime)
date($format = "Y-m-d")
Check if is a date and time
@param string $format validate after this date format (default Y-m-d H:i)
@return bool|inst(dateTime)
dateTime($format = "Y-m-d H:i")
Check if is a date and time
@param string $format validate after this date format (default Y-m-d H:i)
@return bool|inst(dateTime)
time($format = "H:i")
Check if is a date and a "valid range"
@param string $format validate after this date format (default Y-m-d H:i)
@return bool / array(T1, T2); T1 = start and T2 = end
dateRange($format = "Y-m-d H:i")
Check "minimum" age (value format should be validate date "Y-m-d")
@param int $a 18 == user should be atleast 18 years old
@return [type] [description]
age(int $a)
Check if is valid domain
@param boolean $flag stricter = true
@return bool
domain($flag = true)
Check if is valid URL (http|https is required)
@return bool
url()
Check if "Host|domain" has an valid DNS (will check A, AAAA and MX)
@return bool
dns()
Match DNS record by search for TYPE and matching VALUE
@param int $type (DNS_A, DNS_CNAME, DNS_HINFO, DNS_CAA, DNS_MX, DNS_NS, DNS_PTR, DNS_SOA, DNS_TXT, DNS_AAAA, DNS_SRV, DNS_NAPTR, DNS_A6, DNS_ALL or DNS_ANY)
@param string $value IPv4, IPv6, String, txt
@return false/array
matchDNS(int $type, string $value)
Validate multiple. Will return true if "one" matches
@param [type] $arr [description]
@return [type] [description]
oneOf(array $arr)
Validate multiple. Will return true if "all" matches
@param [type] $arr [description]
@return [type] [description]
allOf(array $arr)