Pionia Core

Validator
in package
Uses ValidationTrait

Table of Contents

Properties

$ip_pattern  : string
$password_pattern  : string
$phone_pattern  : string
$slug_pattern  : string
$hayStack  : Arrayable|null
$hook  : string
$throwsExceptions  : bool

Methods

allShouldBe()  : Validator
asDomain()  : Validator
asEmail()  : Validator
Validates emails of all formats
asInternationalPhone()  : bool|int
Will only validate international numbers if the code is provided, otherwise, will validate local only
asIp()  : Validator
asMac()  : Validator
asNumber()  : static
asNumeric()  : static
asNumericInt()  : static
asPassword()  : static
Validates the rules as follows - At least one integer - At least one lowercase alpha letter - At least one Uppercase alpha letter - At least one special character
asSlug()  : Validator
asUrl()  : Validator
validate()  : static
_validate()  : bool|int
Use this to cover scenarios this contract does not cover
_validateFilter()  : int|bool
Internal validator based on PHP filter_var validations
getOrFail()  : mixed
shouldBe()  : Validator

Properties

$ip_pattern

public string $ip_pattern = "/^(\\d{1,3}\\.){3}\\d{1,3}\$/"

$password_pattern

public string $password_pattern = "/^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*(_|[^\\w])).+\$/"

$phone_pattern

public string $phone_pattern = "/^[+]{1}(?:[0-9\\-\\(\\)\\/.]\\s?){6,15}[0-9]{1}\$/"

Methods

allShouldBe()

public allShouldBe(string $expected[, string|null $message = 'Invalid data' ]) : Validator
Parameters
$expected : string
$message : string|null = 'Invalid data'
Tags
throws
Exception
Return values
Validator

asDomain()

public asDomain([string|null $regex = null ]) : Validator
Parameters
$regex : string|null = null

Your custom regular expression we can depend on instead.

Tags
throws
Exception
Return values
Validator

asEmail()

Validates emails of all formats

public asEmail([string|null $regex = null ][, string|null $message = 'Invalid email address' ]) : Validator
Parameters
$regex : string|null = null
$message : string|null = 'Invalid email address'
Tags
throws
Exception
Return values
Validator

asInternationalPhone()

Will only validate international numbers if the code is provided, otherwise, will validate local only

public asInternationalPhone([string|null $code = null ][, string|null $regex = null ][, string|null $message = 'Invalid phone number' ]) : bool|int
Parameters
$code : string|null = null

International country that you want to check against

$regex : string|null = null

Your custom regular expression we can depend on instead.

$message : string|null = 'Invalid phone number'
Tags
throws
Exception
Return values
bool|int

asIp()

public asIp([string|null $regex = null ][, string|null $message = 'Invalid IP address' ]) : Validator
Parameters
$regex : string|null = null

Your custom regular expression we can depend on instead.

$message : string|null = 'Invalid IP address'
Tags
throws
Exception
Return values
Validator

asMac()

public asMac([string|null $regex = null ]) : Validator
Parameters
$regex : string|null = null

Your custom regular expression we can depend on instead.

Tags
throws
Exception
Return values
Validator

asNumber()

public asNumber([string|null $message = 'Invalid Number' ]) : static
Parameters
$message : string|null = 'Invalid Number'
Tags
throws
Exception
Return values
static

asNumeric()

public asNumeric([string|null $message = 'Invalid Numeric' ]) : static
Parameters
$message : string|null = 'Invalid Numeric'
Tags
throws
Exception
Return values
static

asNumericInt()

public asNumericInt([string|null $message = 'Invalid Numeric Integer' ]) : static
Parameters
$message : string|null = 'Invalid Numeric Integer'
Tags
throws
Exception
Return values
static

asPassword()

Validates the rules as follows - At least one integer - At least one lowercase alpha letter - At least one Uppercase alpha letter - At least one special character

public asPassword([string|null $regex = null ][, string|null $message = 'Week Password' ]) : static
Parameters
$regex : string|null = null

Your custom regular expression we can depend on instead.

$message : string|null = 'Week Password'
Tags
throws
Exception
Return values
static

asSlug()

public asSlug([string|null $regex = null ]) : Validator
Parameters
$regex : string|null = null

Your custom regular expression we can depend on instead.

Tags
throws
Exception
example
$slug = 'fsjkfjshfsjk-skdhfkjdfsj-skdjfhjskdf'; // valid slug
$slug2 = 'sfksdfsdskljfhsdhjkfhsdsfsdfsfsd'; // valid slug
$slug3 = 'dkfl ksjfhsdk/skjdfsk%'; // invalid slug
Return values
Validator

asUrl()

public asUrl([string|null $regex = null ][, string|null $message = 'Invalid URL' ]) : Validator
Parameters
$regex : string|null = null

Your custom regular expression we can depend on instead.

$message : string|null = 'Invalid URL'
Tags
throws
Exception
Return values
Validator

validate()

public static validate(string $keyToValidate, Arrayable|null $data) : static
Parameters
$keyToValidate : string
$data : Arrayable|null
Return values
static

_validate()

Use this to cover scenarios this contract does not cover

private _validate(string $regex[, string|null $message = 'Invalid data' ]) : bool|int
Parameters
$regex : string
  • The regular expression to check against
$message : string|null = 'Invalid data'
  • The message to throw if the value is invalid and we are in the exceptions mode
Tags
throws
Exception
Return values
bool|int

_validateFilter()

Internal validator based on PHP filter_var validations

private _validateFilter( $filterType[, string $message = 'Invalid Data' ]) : int|bool
Parameters
$filterType :
$message : string = 'Invalid Data'
Tags
throws
Exception
Return values
int|bool

shouldBe()

private shouldBe(mixed $expected[, string|null $message = 'Invalid data' ]) : Validator
Parameters
$expected : mixed
$message : string|null = 'Invalid data'
Tags
throws
Exception
Return values
Validator

        
On this page

Search results