Menu

## ValidationTrait

ValidationTrait.php : 8

### Table of Contents

#### Properties

$ip_pattern : string
$password_pattern : string
$phone_pattern : string
$slug_pattern : string
$throwsExceptions : bool

#### Methods

__construct() : mixed
allShouldBe() : mixed
asDomain() : bool|int
asEmail() : bool|int
  Validates emails of all formats
asInternationalPhone() : bool|int
  Will only validate international numbers if the code is provided, otherwise, will validate local only
asIp() : bool|int
asMac() : bool|int
asNumber() : bool
asNumeric() : bool|int
asNumericInt() : bool|int
asPassword() : bool|int
  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() : bool|int
asUrl() : bool|int
validate() : bool|int
  Use this to cover scenarios this contract does not cover
_validateFilter() : int|bool
  Internal validator based on PHP filter_var validations
shouldBe() : bool

### Properties

#### $ip_pattern

ValidationTrait.php : 12
`public string $ip_pattern = "/^(\\d{1,3}\\.){3}\\d{1,3}\$/"`

#### $password_pattern

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

#### $phone_pattern

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

#### $slug_pattern

ValidationTrait.php : 13
`public string $slug_pattern = "/^[a-z0-9-]+\$/"`

#### $throwsExceptions

ValidationTrait.php : 14
`private bool $throwsExceptions = true`

### Methods

#### __construct()

ValidationTrait.php : 16
`public __construct([mixed $throws = true ]) : mixed`

##### Parameters

$throws : mixed = true

#### allShouldBe()

ValidationTrait.php : 220
`public allShouldBe(iterable<string|int, mixed> $value, string $expected) : mixed`

##### Parameters

$value : iterable<string|int, mixed>
$expected : string

##### Tags

throws
  InvalidDataException

#### asDomain()

ValidationTrait.php : 165
`public asDomain(mixed $domain[, string|null $regex = null ]) : bool|int`

##### Parameters

$domain : mixed

  The domain we are testing its validity

$regex : string|null = null

  Your custom regular expression we can depend on instead.

##### Tags

throws
  InvalidDataException

##### Return values

bool|int

#### asEmail()

ValidationTrait.php : 43

Validates emails of all formats

`public asEmail(string $email) : bool|int`

##### Parameters

$email : string

  The email address we're currently testing in the core.

##### Tags

throws
  InvalidDataException

##### Return values

bool|int

#### asInternationalPhone()

ValidationTrait.php : 57

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

`public asInternationalPhone(string $phone[, string|null $code = null ][, string|null $regex = null ]) : bool|int`

##### Parameters

$phone : string

  The phone number we are testing

$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.

##### Tags

throws
  InvalidDataException

##### Return values

bool|int

#### asIp()

ValidationTrait.php : 136
`public asIp(mixed $ip[, string|null $regex = null ]) : bool|int`

##### Parameters

$ip : mixed

  The Ip address we're checking.

$regex : string|null = null

  Your custom regular expression we can depend on instead.

##### Tags

throws
  InvalidDataException

##### Return values

bool|int

#### asMac()

ValidationTrait.php : 150
`public asMac(mixed $mac[, string|null $regex = null ]) : bool|int`

##### Parameters

$mac : mixed

  The mac address we are checking

$regex : string|null = null

  Your custom regular expression we can depend on instead.

##### Tags

throws
  InvalidDataException

##### Return values

bool|int

#### asNumber()

ValidationTrait.php : 92
`public asNumber(mixed $number) : bool`

##### Parameters

$number : mixed

  The number we are checking

##### Tags

throws
  InvalidDataException

##### Return values

bool

#### asNumeric()

ValidationTrait.php : 100
`public asNumeric(mixed $number) : bool|int`

##### Parameters

$number : mixed

##### Tags

throws
  InvalidDataException

##### Return values

bool|int

#### asNumericInt()

ValidationTrait.php : 108
`public asNumericInt(mixed $number) : bool|int`

##### Parameters

$number : mixed

##### Tags

throws
  InvalidDataException

##### Return values

bool|int

#### asPassword()

ValidationTrait.php : 82

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(mixed $password[, string|null $regex = null ]) : bool|int`

##### Parameters

$password : mixed

  The password string we are testing, must be raw, not hashed

$regex : string|null = null

  Your custom regular expression we can depend on instead.

##### Tags

throws
  InvalidDataException

##### Return values

bool|int

#### asSlug()

ValidationTrait.php : 186
`public asSlug(mixed $slug[, string|null $regex = null ]) : bool|int`

##### Parameters

$slug : mixed

  The slug string we are testing

$regex : string|null = null

  Your custom regular expression we can depend on instead.

##### Tags

example

      $slug = 'fsjkfjshfsjk-skdhfkjdfsj-skdjfhjskdf'; // valid slug
      $slug2 = 'sfksdfsdskljfhsdhjkfhsdsfsdfsfsd'; // valid slug
      $slug3 = 'dkfl ksjfhsdk/skjdfsk%'; // invalid slug

throws
  InvalidDataException

##### Return values

bool|int

#### asUrl()

ValidationTrait.php : 122
`public asUrl(mixed $url[, string|null $regex = null ]) : bool|int`

##### Parameters

$url : mixed

  The url string we are testing

$regex : string|null = null

  Your custom regular expression we can depend on instead.

##### Tags

throws
  InvalidDataException

##### Return values

bool|int

#### validate()

ValidationTrait.php : 29

Use this to cover scenarios this contract does not cover

`public validate(string $regex, mixed $value[, string|null $message = 'Invalid data' ]) : bool|int`

##### Parameters

$regex : string
  - The regular expression to check against
$value : mixed
  - The value to check
$message : string|null = 'Invalid data'
  - The message to throw if the value is invalid and we are in the exceptions mode

##### Tags

throws
  InvalidDataException

##### Return values

bool|int

#### _validateFilter()

ValidationTrait.php : 200

Internal validator based on PHP filter_var validations

`private _validateFilter(mixed $value, $filterType[, string $message = 'Invalid Data' ]) : int|bool`

##### Parameters

$value : mixed
$filterType :
$message : string = 'Invalid Data'

##### Tags

throws
  InvalidDataException

##### Return values

int|bool

#### shouldBe()

ValidationTrait.php : 212
`private shouldBe(mixed $value, mixed $expected) : bool`

##### Parameters

$value : mixed
$expected : mixed

##### Tags

throws
  InvalidDataException

##### Return values

bool

## Search results