class Validate (View source)

Class toolbox to validate values

Properties

DoliDB $db
Translate $outputLang
$error

Methods

__construct(DoliDB $db, Translate $outputLang = null)

Constructor

void
clear()

Use to clear errors msg or other ghost vars

void
setError(string $errMsg)

Use to clear errors msg or other ghost vars

bool
isEmail(string $email, int $maxLength = 0)

Check for e-mail validity

bool
isPrice(string $price)

Check for price validity

bool
isTimestamp(string|int $stamp)

Check for timestamp validity

bool
isPhone(string $phone)

Check for phone validity

bool
isMaxLength(string $string, int $length)

Check for string max length validity

bool
isNotEmptyString(string $string)

Check for string not empty

bool
isMinLength(string $string, int $length)

Check for string min length validity

bool
isUrl(string $url)

Check url validity

bool
isDuration(mixed $duration)

Check Duration validity

bool
isNumeric(mixed $string)

Check numeric validity

bool
isBool(mixed $bool)

Check for boolean validity

bool
isInDb(string[] $values, string $table, string $col)

Check for all values in db

bool
isFetchable(int $id, string $classname, string $classpath)

Check for all values in db

bool
isFetchableElement(int $id, string $element_type)

Check for all values in db for an element

Details

__construct(DoliDB $db, Translate $outputLang = null)

Constructor

Parameters

DoliDB $db

Database handler

Translate $outputLang

Output lang for error

protected void clear()

Use to clear errors msg or other ghost vars

Return Value

void

protected void setError(string $errMsg)

Use to clear errors msg or other ghost vars

Parameters

string $errMsg

your error message

Return Value

void

bool isEmail(string $email, int $maxLength = 0)

Check for e-mail validity

Parameters

string $email

e-mail address to validate

int $maxLength

string max length (not used)

Return Value

bool

Validity is ok or not

bool isPrice(string $price)

Check for price validity

Parameters

string $price

Price to validate

Return Value

bool

Validity is ok or not

bool isTimestamp(string|int $stamp)

Check for timestamp validity

Parameters

string|int $stamp

timestamp to validate

Return Value

bool

Validity is ok or not

bool isPhone(string $phone)

Check for phone validity

Parameters

string $phone

Phone string to validate

Return Value

bool

Validity is ok or not

bool isMaxLength(string $string, int $length)

Check for string max length validity

Parameters

string $string

to validate

int $length

max length

Return Value

bool

Validity is ok or not

bool isNotEmptyString(string $string)

Check for string not empty

Parameters

string $string

to validate

Return Value

bool

Validity is ok or not

bool isMinLength(string $string, int $length)

Check for string min length validity

Parameters

string $string

to validate

int $length

max length

Return Value

bool

Validity is ok or not

bool isUrl(string $url)

Check url validity

Parameters

string $url

to validate

Return Value

bool

Validity is ok or not

bool isDuration(mixed $duration)

Check Duration validity

Parameters

mixed $duration

to validate

Return Value

bool

Validity is ok or not

bool isNumeric(mixed $string)

Check numeric validity

Parameters

mixed $string

to validate

Return Value

bool

Validity is ok or not

bool isBool(mixed $bool)

Check for boolean validity

Parameters

mixed $bool

Value to validate, may not be bool

Return Value

bool

Validity is ok or not

bool isInDb(string[] $values, string $table, string $col)

Check for all values in db

Parameters

string[] $values

Boolean to validate

string $table

the db table name without $this->db->prefix()

string $col

the target col

Return Value

bool

Validity is ok or not

Exceptions

Exception

bool isFetchable(int $id, string $classname, string $classpath)

Check for all values in db

Parameters

int $id

of element

string $classname

the class name

string $classpath

the class path

Return Value

bool

Validity is ok or not

Exceptions

Exception

bool isFetchableElement(int $id, string $element_type)

Check for all values in db for an element

Parameters

int $id

Element Id

string $element_type

The element type

Return Value

bool

Validity is ok or not

Exceptions

Exception

See also

\self::isFetchable()