class CRM_Utils_Rule

Class CRM_Utils_Rule

Methods

static bool
title($str, int $maxLength = 127)

No description

static bool
longTitle($str)

No description

static bool
variable($str)

No description

static bool
mysqlColumnNameOrAlias($str)

Validate that a string is a valid MySQL column name or alias.

static bool
mysqlOrderByDirection($str)

Validate that a string is ASC or DESC.

static bool
mysqlOrderBy($str)

Validate that a string is valid order by clause.

static bool
qfVariable($str)

No description

static bool
phone($phone)

No description

static bool
query($query)

No description

static bool
url($url)

No description

static bool
urlish($url)

No description

static bool
wikiURL($string)

No description

static bool
domain($domain)

No description

static null
date($value, null $default = NULL)

No description

static null|string
dateTime($value, null $default = NULL)

No description

static bool
currentDate(array $date, bool $monthRequired = TRUE)

Check the validity of the date (in qf format) note that only a year is valid, or a mon-year is also valid in addition to day-mon-year. The date specified has to be beyond today. (i.e today or later)

static bool
mysqlDate(string $date)

Check the validity of a date or datetime (timestamp) value which is in YYYYMMDD or YYYYMMDDHHMMSS format

static bool
integer($value)

No description

static bool
positiveInteger($value)

No description

static bool
commaSeparatedIntegers($value)

No description

static bool
numeric($value)

No description

static bool
alphanumeric($value)

Test whether $value is alphanumeric.

static bool
numberOfDigit($value, $noOfDigit)

No description

static bool
color($value)

Strict validation of 6-digit hex color notation per html5

static string
cleanMoney(string $value)

Strip thousand separator from a money string.

static bool
money($value)

No description

static bool
string($value, int $maxLength = 0)

No description

static bool
boolean($value)

No description

static bool
email($value)

No description

static bool
emailList($list)

No description

static bool
postalCode($value)

allow between 4-6 digits as postal code since india needs 6 and US needs 5 (or if u disregard the first 0, 4 (thanx excel!) FIXME: we need to figure out how to localize such rules

static bool
asciiFile(string $elementValue)

See how file rules are written in HTML/QuickForm/file.php Checks to make sure the uploaded file is ascii

static bool
utf8File(array $elementValue)

Checks to make sure the uploaded file is in UTF-8, recodes if it's not

static bool
htmlFile(array $elementValue)

See how file rules are written in HTML/QuickForm/file.php Checks to make sure the uploaded file is html

static bool
objectExists(string $value, array $options)

Check if there is a record with the same name in the db.

static bool
optionExists($value, $options)

No description

static bool
creditCardNumber($value, $type)

No description

static bool
cvv($value, $type)

No description

static bool
currencyCode($value)

No description

static bool
xssString($value)

No description

static bool
json(string $value)

Validate json string for xss

static bool
fileExists($path)

No description

static bool
settingPath(string $path)

Determine whether the value contains a valid reference to a directory.

static bool
validContact($value, null $actualElementValue = NULL)

No description

static bool
qfDate(array $date)

Check the validity of the date (in qf format) note that only a year is valid, or a mon-year is also valid in addition to day-mon-year

static bool
qfKey($key)

No description

static 
validDateRange(array $fields, $fieldName, $errors, $title)

Check if the values in the date range are in correct chronological order.

static bool
checkExtensionKeyIsValid(string $key = NULL)

No description

static bool
arrayValue(array $array)

Validate array recursively checking keys and values.

Details

at line 47
static bool title($str, int $maxLength = 127)

Parameters

$str
int $maxLength

Return Value

bool

at line 67
static bool longTitle($str)

Parameters

$str

Return Value

bool

at line 76
static bool variable($str)

Parameters

$str

Return Value

bool

at line 97
static bool mysqlColumnNameOrAlias($str)

Validate that a string is a valid MySQL column name or alias.

Parameters

$str

Return Value

bool

at line 126
static bool mysqlOrderByDirection($str)

Validate that a string is ASC or DESC.

Empty string should be treated as invalid and ignored => default = ASC.

Parameters

$str

Return Value

bool

at line 140
static bool mysqlOrderBy($str)

Validate that a string is valid order by clause.

Parameters

$str

Return Value

bool

at line 173
static bool qfVariable($str)

Parameters

$str

Return Value

bool

at line 194
static bool phone($phone)

Parameters

$phone

Return Value

bool

at line 212
static bool query($query)

Parameters

$query

Return Value

bool

at line 231
static bool url($url)

Parameters

$url

Return Value

bool

at line 248
static bool urlish($url)

Parameters

$url

Return Value

bool

at line 261
static bool wikiURL($string)

Parameters

$string

Return Value

bool

at line 271
static bool domain($domain)

Parameters

$domain

Return Value

bool

at line 285
static null date($value, null $default = NULL)

Parameters

$value
null $default

Return Value

null

at line 300
static null|string dateTime($value, null $default = NULL)

Parameters

$value
null $default

Return Value

null|string

at line 324
static bool currentDate(array $date, bool $monthRequired = TRUE)

Check the validity of the date (in qf format) note that only a year is valid, or a mon-year is also valid in addition to day-mon-year. The date specified has to be beyond today. (i.e today or later)

Parameters

array $date
bool $monthRequired Check whether month is mandatory.

Return Value

bool true if valid date

at line 415
static bool mysqlDate(string $date)

Check the validity of a date or datetime (timestamp) value which is in YYYYMMDD or YYYYMMDDHHMMSS format

Uses PHP checkdate() - params are ( int $month, int $day, int $year )

Parameters

string $date

Return Value

bool true if valid date

at line 433
static bool integer($value)

Parameters

$value

Return Value

bool

at line 466
static bool positiveInteger($value)

Parameters

$value

Return Value

bool

at line 489
static bool commaSeparatedIntegers($value)

Parameters

$value

Return Value

bool

at line 505
static bool numeric($value)

Parameters

$value

Return Value

bool

at line 531
static bool alphanumeric($value)

Test whether $value is alphanumeric.

Underscores and dashes are also allowed!

This is the type of string you could expect to see in URL parameters like ?mode=live vs ?mode=test. This function exists so that we can be strict about what we accept for such values, thus mitigating against potential security issues.

Parameters

$value

Return Value

bool

See also

CRM_Utils_RuleTest::alphanumericData for examples of vales that give TRUE/FALSE here

at line 541
static bool numberOfDigit($value, $noOfDigit)

Parameters

$value
$noOfDigit

Return Value

bool

at line 551
static bool color($value)

Strict validation of 6-digit hex color notation per html5

Parameters

$value

Return Value

bool

at line 566
static string cleanMoney(string $value)

Strip thousand separator from a money string.

Note that this should be done at the form layer. Once we are processing money at the BAO or processor layer we should be working with something that is already in a normalised format.

Parameters

string $value

Return Value

string

at line 614
static bool money($value)

Parameters

$value

Return Value

bool

at line 646
static bool string($value, int $maxLength = 0)

Parameters

$value
int $maxLength

Return Value

bool

at line 660
static bool boolean($value)

Parameters

$value

Return Value

bool

at line 671
static bool email($value)

Parameters

$value

Return Value

bool

at line 680
static bool emailList($list)

Parameters

$list

Return Value

bool

at line 699
static bool postalCode($value)

allow between 4-6 digits as postal code since india needs 6 and US needs 5 (or if u disregard the first 0, 4 (thanx excel!) FIXME: we need to figure out how to localize such rules

Parameters

$value

Return Value

bool

at line 715
static bool asciiFile(string $elementValue)

See how file rules are written in HTML/QuickForm/file.php Checks to make sure the uploaded file is ascii

Parameters

string $elementValue

Return Value

bool True if file has been uploaded, false otherwise

at line 732
static bool utf8File(array $elementValue)

Checks to make sure the uploaded file is in UTF-8, recodes if it's not

Parameters

array $elementValue

Return Value

bool Whether file has been uploaded properly and is now in UTF-8.

at line 762
static bool htmlFile(array $elementValue)

See how file rules are written in HTML/QuickForm/file.php Checks to make sure the uploaded file is html

Parameters

array $elementValue

Return Value

bool True if file has been uploaded, false otherwise

at line 782
static bool objectExists(string $value, array $options)

Check if there is a record with the same name in the db.

Parameters

string $value The value of the field we are checking.
array $options The daoName, fieldName (optional) and DomainID (optional).

Return Value

bool true if object exists

at line 797
static bool optionExists($value, $options)

Parameters

$value
$options

Return Value

bool

at line 807
static bool creditCardNumber($value, $type)

Parameters

$value
$type

Return Value

bool

at line 817
static bool cvv($value, $type)

Parameters

$value
$type

Return Value

bool

at line 826
static bool currencyCode($value)

Parameters

$value

Return Value

bool

at line 842
static bool xssString($value)

Parameters

$value

Return Value

bool

at line 861
static bool json(string $value)

Validate json string for xss

Parameters

string $value

Return Value

bool False if invalid, true if valid / safe.

at line 877
static bool fileExists($path)

Parameters

$path

Return Value

bool

at line 890
static bool settingPath(string $path)

Determine whether the value contains a valid reference to a directory.

Paths stored in the setting system may be absolute -- or may be relative to the default data directory.

Parameters

string $path

Return Value

bool

at line 900
static bool validContact($value, null $actualElementValue = NULL)

Parameters

$value
null $actualElementValue

Return Value

bool

at line 918
static bool qfDate(array $date)

Check the validity of the date (in qf format) note that only a year is valid, or a mon-year is also valid in addition to day-mon-year

Parameters

array $date

Return Value

bool true if valid date

at line 965
static bool qfKey($key)

Parameters

$key

Return Value

bool

at line 981
static validDateRange(array $fields, $fieldName, $errors, $title)

Check if the values in the date range are in correct chronological order.

Parameters

array $fields Fields of the form.
$fieldName Name of date range field.
$errors The error array.
$title Title of the date range to be displayed in the error message.

at line 994
static bool checkExtensionKeyIsValid(string $key = NULL)

Parameters

string $key Extension Key to check

Return Value

bool

at line 1007
static protected bool arrayValue(array $array)

Validate array recursively checking keys and values.

Parameters

array $array

Return Value

bool