class StringRule implements Stringable (View source)

Traits

Properties

protected array $constraints

The constraints for the string rule.

Methods

$this|TWhenReturnType
when(TWhenParameter|TWhenParameter|null $value = null, callable|null $callback = null, callable|null $default = null)

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

$this|TUnlessReturnType
unless(TUnlessParameter|TUnlessParameter|null $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

$this|TWhenReturnType when(TWhenParameter|TWhenParameter|null $value = null, callable|null $callback = null, callable|null $default = null)

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

Parameters

TWhenParameter|TWhenParameter|null $value
callable|null $callback
callable|null $default

Return Value

$this|TWhenReturnType

$this|TUnlessReturnType unless(TUnlessParameter|TUnlessParameter|null $value = null, callable|null $callback = null, callable|null $default = null)

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

Parameters

TUnlessParameter|TUnlessParameter|null $value
callable|null $callback
callable|null $default

Return Value

$this|TUnlessReturnType

StringRule alpha(bool $ascii = false)

The field under validation must be entirely alphabetic characters.

Parameters

bool $ascii

Return Value

StringRule

StringRule alphaDash(bool $ascii = false)

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

Parameters

bool $ascii

Return Value

StringRule

StringRule alphaNumeric(bool $ascii = false)

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

Parameters

bool $ascii

Return Value

StringRule

StringRule ascii()

The field under validation must be entirely ASCII characters.

Return Value

StringRule

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

StringRule doesntEndWith(string ...$values)

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

Parameters

string ...$values

Return Value

StringRule

StringRule doesntStartWith(string ...$values)

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

Parameters

string ...$values

Return Value

StringRule

StringRule endsWith(string ...$values)

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

Parameters

string ...$values

Return Value

StringRule

StringRule exactly(int $value)

The field under validation must have an exact length.

Parameters

int $value

Return Value

StringRule

StringRule lowercase()

The field under validation must be entirely lowercase.

Return Value

StringRule

StringRule max(int $value)

The field under validation must not exceed the given length.

Parameters

int $value

Return Value

StringRule

StringRule min(int $value)

The field under validation must have a minimum length.

Parameters

int $value

Return Value

StringRule

StringRule startsWith(string ...$values)

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

Parameters

string ...$values

Return Value

StringRule

StringRule uppercase()

The field under validation must be entirely uppercase.

Return Value

StringRule

string __toString()

Convert the rule to a validation string.

Return Value

string

protected StringRule addRule(array|string $rules)

Add custom rules to the validation rules array.

Parameters

array|string $rules

Return Value

StringRule

Laravel Cloud is the best place to deploy Laravel, Nuxt, Express, Hono, Node.js, Bun, Go, Flask, Python, and more, with dedicated infrastructure available on AWS through Laravel Private Cloud.