class StringRule implements Stringable

Traits

Properties

protected array $constraints

The constraints for the string rule.

Methods

mixed
when(mixed $value = null, callable|null $callback = null, callable|null $default = null)

Apply the callback if the given "value" is (or resolves to) truthy.

mixed
unless(mixed $value = null, callable|null $callback = null, callable|null $default = null)

Apply the callback if the given "value" is (or resolves to) falsy.

alpha(bool $ascii = false)

The field under validation must be entirely alphabetic characters.

alphaDash(bool $ascii = false)

The field under validation must be entirely alpha-numeric characters, dashes, and underscores.

alphaNumeric(bool $ascii = false)

The field under validation must be entirely alpha-numeric characters.

ascii()

The field under validation must be entirely ASCII characters.

between(int $min, int $max)

The field under validation must have a length between the given min and max (inclusive).

doesntEndWith(string ...$values)

The field under validation must not end with any of the given values.

doesntStartWith(string ...$values)

The field under validation must not start with any of the given values.

endsWith(string ...$values)

The field under validation must end with one of the given values.

exactly(int $value)

The field under validation must have an exact length.

lowercase()

The field under validation must be entirely lowercase.

max(int $value)

The field under validation must not exceed the given length.

min(int $value)

The field under validation must have a minimum length.

startsWith(string ...$values)

The field under validation must start with one of the given values.

uppercase()

The field under validation must be entirely uppercase.

string
__toString()

Convert the rule to a validation string.

addRule(array|string $rules)

Add custom rules to the validation rules array.

Details

in Conditionable at line 23
mixed when(mixed $value = null, callable|null $callback = null, callable|null $default = null)

Apply the callback if the given "value" is (or resolves to) truthy.

Parameters

mixed $value
callable|null $callback
callable|null $default

Return Value

mixed

in Conditionable at line 56
mixed unless(mixed $value = null, callable|null $callback = null, callable|null $default = null)

Apply the callback if the given "value" is (or resolves to) falsy.

Parameters

mixed $value
callable|null $callback
callable|null $default

Return Value

mixed

at line 23
StringRule alpha(bool $ascii = false)

The field under validation must be entirely alphabetic characters.

Parameters

bool $ascii

Return Value

StringRule

at line 31
StringRule alphaDash(bool $ascii = false)

The field under validation must be entirely alpha-numeric characters, dashes, and underscores.

Parameters

bool $ascii

Return Value

StringRule

at line 39
StringRule alphaNumeric(bool $ascii = false)

The field under validation must be entirely alpha-numeric characters.

Parameters

bool $ascii

Return Value

StringRule

at line 47
StringRule ascii()

The field under validation must be entirely ASCII characters.

Return Value

StringRule

at line 55
StringRule between(int $min, int $max)

The field under validation must have a length between the given min and max (inclusive).

Parameters

int $min
int $max

Return Value

StringRule

at line 63
StringRule doesntEndWith(string ...$values)

The field under validation must not end with any of the given values.

Parameters

string ...$values

Return Value

StringRule

at line 71
StringRule doesntStartWith(string ...$values)

The field under validation must not start with any of the given values.

Parameters

string ...$values

Return Value

StringRule

at line 79
StringRule endsWith(string ...$values)

The field under validation must end with one of the given values.

Parameters

string ...$values

Return Value

StringRule

at line 87
StringRule exactly(int $value)

The field under validation must have an exact length.

Parameters

int $value

Return Value

StringRule

at line 95
StringRule lowercase()

The field under validation must be entirely lowercase.

Return Value

StringRule

at line 103
StringRule max(int $value)

The field under validation must not exceed the given length.

Parameters

int $value

Return Value

StringRule

at line 111
StringRule min(int $value)

The field under validation must have a minimum length.

Parameters

int $value

Return Value

StringRule

at line 119
StringRule startsWith(string ...$values)

The field under validation must start with one of the given values.

Parameters

string ...$values

Return Value

StringRule

at line 127
StringRule uppercase()

The field under validation must be entirely uppercase.

Return Value

StringRule

at line 135
string __toString()

Convert the rule to a validation string.

Return Value

string

at line 143
protected StringRule addRule(array|string $rules)

Add custom rules to the validation rules array.

Parameters

array|string $rules

Return Value

StringRule