Class containing static methods to aid Validation

package dstruct_common

 Methods

Is the string a known API?

isAPI(\unknown $api, \number $host) : boolean | \unknown | \Ambigous
Static
todo Shane.... wft?

Parameters

$api

\unknown

$host

\number

Returns

boolean\unknown\Ambigous<>|string

Validate input contains only alphas

isAlpha(string $value) : boolean
Static

Parameters

$value

string

Returns

boolean

Check input only contains letters and numbers.

isAlphaNumeric(string $value, string $allowablechars) : boolean
Static
todo split method from allowablechars stuff!

Parameters

$value

string

String to validate

$allowablechars

string

Exceptions

\DStructGeneralException

Returns

boolean

Validate format for bank account number.

isBankAccountNumber(integer $number) : boolean
Static

Bank account numbers are just 8 numeric characters.

todo Just us a regex? Do we even need this? Better to keep it as ppl may get confused with leading zeros??

Parameters

$number

integer

Returns

boolean

Validate a two-letter country code.

isCountryCode(string $code) : boolean
Static
todo What about upper case stuff...?? Make it a param?
tod What about method to return the country name and vice verse

Parameters

$code

string

Returns

boolean

Check whether a date is valid'

isDate(string $date) : boolean
Static
todo Only checks a very specific format!

Parameters

$date

string

Format dd/mm/yyyy

Returns

boolean

Is a valid domain part.

isDomain(string $domain) : boolean
Static

Can't use FILTERs because they require scheme etc (docs are incorrect and flags do nothing). Many solutions on the internet were examined for checking domains, but all of them failed at least one test! Also, the PHP filter is broken at the time of writting.

author David Lidstone

Parameters

$domain

string

Returns

boolean

Checks that an email address is a valid format.

isEmailAddress(string $input) : boolean
Static

N.B. This is NOT a check that the email EXISTS.

Parameters

$input

string

Returns

boolean

Is string valid as a Google Analytics Key?

isGoogleAnalyticsKey(string $key) : boolean
Static

WARNING: This is based on rather uncertain data... it seems to fit all keys tried so far, but Google may issue keys which don't fit this validation. Please let us know of any which don't validate but are genuine. Also, not that successful validation does not mean that the key is VALID with Google, just that is fits the format of a key.

Parameters

$key

string

Returns

boolean

Is a value a 'plain' numeric?

isNumeric(mixed $value, boolean $allowdecimal, boolean $allowsigned) : boolean
Static

PHP's built-in is_numeric() function also allows some more exotic values such as hex, leading + chars and scientific notation.
PHP's ctype_digit() also checks type and requires an int... this can cause validation failures, particularly when using data from forms.

Parameters

$value

mixed

String or Int to test

$allowdecimal

boolean

Allow decimal places

$allowsigned

boolean

Allow values with negative sign char

Returns

boolean

Is valid postcode format?

isPostcode(string $pc) : boolean
Static

See wikipedia for more info. Case insensitive. Regex from wikipedia?

Parameters

$pc

string

Postcode to check

Returns

boolean

Is valid UK Bank SortCode.

isSortCode(string $sortcode) : boolean
Static
todo changed, needs checking

Parameters

$sortcode

string

SortCode to check

Returns

boolean

Checks whether string is 'strong'.

isStrongPassword(string $password, integer $minlength, boolean $numeric, boolean $casechange) 
Static

Fails if string is less than parsed length. Default is 8 characters. Fails if less than half the characters in the string are different. Default set to check for numeric characters fails if false If you expect non-ASCII compatible charactersets then dont use casechange. If you are using Western characterset then it is OK to use casechange

returns boolean

Parameters

$password

string

Password to check

$minlength

integer

Minimum allowable length of password.

$numeric

boolean

Fail if there aren't numeric characters in the password.

$casechange

boolean

Check that there are upper and lower case characters.

Is (UK) telephone number format.

isTelephoneNumber(string $telno) : boolean
Static

Only very basic checking. Strips spaces and elipses, checks for numeric and that there is a leading 0. Also checks that the length is 10 to 12 characters.

Parameters

$telno

string

Number to validate

Returns

boolean

Validate a date input in the format dd/mm/yyyy.

isUserDate(string $userdate, string $datename, \ProjectError $errobj) : boolean
Static

Populates ProjectError with error strings using $datename as field.

todo only validates in the format dd/mm/yyyyy!

Parameters

$userdate

string

$datename

string

$errobj

\ProjectError

Returns

boolean

Validate a time input in the format hh:mm:ss

isUserTime(string $usertime, string $tsname, \ProjectError $errobj) : boolean
Static

Populates ProjectError with error strings using $tsname as field.

Parameters

$usertime

string

$tsname

string

$errobj

\ProjectError

Returns

boolean

Validate a timestamp input in the format dd/mm/yyyy hh:mm:ss

isUserTimestamp(string $date, string $tsname, \ProjectError $errobj) : boolean
Static

Populates ProjectError with error strings using $tsname as field.

Parameters

$date

string

$tsname

string

$errobj

\ProjectError

Returns

boolean

Check whether current OS is windows.

isWindows() : boolean
Static

Returns

boolean

Is input within a range.

isWithinRange(float $value, float $min, float $max) : boolean
Static

Parameters

$value

float

Value to check

$min

float

Minimum allowable value

$max

float

Maximum allowable value

Returns

boolean

String is within a set number of character lengths.

isWithinStringLength(string $str, integer $min, integer $max) : boolean
Static

Parameters

$str

string

String to check

$min

integer

Minimum number of characters

$max

integer

Maximum number of characters

Returns

boolean

Check YouTube video exists???

isYouTubeAPI(\unknown $api) : boolean
Static
todo Downloads whole video to check????? DELETE!?

Parameters

$api

\unknown

Returns

boolean

Class constructor

__construct()