Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
---
title: Validation Rules
---

## Overview

Tempest's validation rules are located in the `Tempest\Validation\Rules` namespace and can be used as attributes on class properties. For detailed information on how to use validation rules, see the [Validation documentation](../2-features/03-validation.md#adding-more-rules).

## Available rules

Tempest provides a comprehensive set of validation rules that can be used with attributes on your class properties. Below is a complete list organized by category:

### String Validation

- **[Alpha](03-alpha.md)** - Validate that a value contains only alphabetic characters
- **[AlphaNumeric](04-alpha-numeric.md)** - Validate that a value contains only alphanumeric characters
- **[DoesNotEndWith](12-does-not-end-with.md)** - Validate that a value does not end with a specific string
- **[DoesNotStartWith](13-does-not-start-with.md)** - Validate that a value does not start with a specific string
- **[EndsWith](15-ends-with.md)** - Validate that a value ends with a specific string
- **[IsString](26-is-string.md)** - Validate that a value is a string
- **[Length](28-length.md)** - Validate the length of a string
- **[Lowercase](29-lowercase.md)** - Validate that a string is lowercase
- **[NotEmpty](32-not-empty.md)** - Validate that a string is not empty
- **[Numeric](35-numeric.md)** - Validate that a value contains only numeric characters
- **[RegEx](39-reg-ex.md)** - Validate that a value matches a regular expression
- **[StartsWith](42-starts-with.md)** - Validate that a value starts with a specific string
- **[Uppercase](47-uppercase.md)** - Validate that a string is uppercase

### Numeric Validation

- **[Between](07-between.md)** - Validate that a value is between a minimum and maximum value
- **[DivisibleBy](11-divisible-by.md)** - Validate that a value is divisible by a specific number
- **[Even](16-even.md)** - Validate if the value is an even number
- **[IsFloat](24-is-float.md)** - Validate that a value is a float
- **[IsInteger](25-is-integer.md)** - Validate that a value is an integer
- **[MultipleOf](31-multiple-of.md)** - Validate that a value is a multiple of a specific number
- **[Odd](36-odd.md)** - Validate if the value is an odd number

### Date & Time Validation

- **[AfterDate](02-after-date.md)** - Validate that a date is after a specific date
- **[BeforeDate](06-before-date.md)** - Validate that a date is before a specific date
- **[BetweenDates](08-between-dates.md)** - Validate that a date is between two other dates
- **[DateTimeFormat](10-date-time-format.md)** - Validate that a value is a date in a specific format
- **[Time](43-time.md)** - Validate that a value is a valid time
- **[Timestamp](44-timestamp.md)** - Validate that a value is a valid timestamp
- **[Timezone](45-timezone.md)** - Validate that a value is a valid timezone

### Array & Collection Validation

- **[ArrayList](05-array-list.md)** - Validate that a value is an array list
- **[Count](09-count.md)** - Validate the number of items in an array
- **[In](18-in.md)** - Validate that a value is one of a given set of values
- **[NotIn](33-not-in.md)** - Validate that a value is not one of a given set of values

### Network & Format Validation

- **[Email](14-email.md)** - Validate that a value is a valid email address
- **[HexColor](17-hex-color.md)** - Validate that a value is a valid hexadecimal color
- **[IP](19-ip.md)** - Validate that a value is a valid IP address
- **[IPv4](20-ipv4.md)** - Validate that a value is a valid IPv4 address
- **[IPv6](21-ipv6.md)** - Validate that a value is a valid IPv6 address
- **[Json](27-json.md)** - Validate that a value is a valid JSON string
- **[MACAddress](30-macaddress.md)** - Validate that a value is a valid MAC address
- **[PhoneNumber](38-phone-number.md)** - Validate that a value is a valid phone number
- **[Ulid](46-ulid.md)** - Validate that a value is a valid ULID
- **[Url](48-url.md)** - Validate that a value is a valid URL
- **[Uuid](49-uuid.md)** - Validate that a value is a valid UUID

### Type & Value Validation

- **[IsBoolean](22-is-boolean.md)** - Validate that a value is a boolean
- **[IsEnum](23-is-enum.md)** - Validate that a value is a valid case for a given enum
- **[NotNull](34-not-null.md)** - Validate that a value is not null
- **[ShouldBeFalse](40-should-be-false.md)** - Validate that a value is false
- **[ShouldBeTrue](41-should-be-true.md)** - Validate that a value is true

### Security Validation

- **[Password](37-password.md)** - Validate that a string is a valid password
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
title: AfterDate
description: "Validate that a date is after a specific date."
---

## Overview

This rule validates whether a given date value is after a specified date. You can also choose to include the specified date in the validation.

## Parameters

- `$date` (`DateTimeInterface|DateTimeImmutable|string`): The date to compare against. Defaults to `now`.
- `$inclusive` (`bool`): Whether to include the specified date in the validation. Defaults to `false`.

## Examples

### After a specific date

```php
use DateTimeImmutable;
use Tempest\Validation\Rules\AfterDate;
use Tempest\DateTime\DateTime;

final class Book
{
#[AfterDate('2023-01-01')]
public DateTime $fooDate;

#[AfterDate(new DateTime('2023-01-01'))]
public DateTime $barDate;

#[AfterDate(new DateTimeImmutable('2023-01-01'))]
public DateTime $bazDate;
}
```

### After a specific date (inclusive)

```php
use Tempest\Validation\Rules\AfterDate;

final class Book
{
#[AfterDate('2023-01-01', inclusive: true)]
public DateTime $fooDate;

#[AfterDate(new DateTime('2023-01-01'), inclusive: true)]
public DateTime $barDate;

#[AfterDate(new DateTimeImmutable('2023-01-01'), inclusive: true)]
public DateTime $bazDate;
}
```

## See also

- [Tempest\Validation\Rules\BeforeDate](06-before-date.md)
- [Tempest\Validation\Rules\BetweenDates](08-between-dates.md)
24 changes: 24 additions & 0 deletions src/Web/Documentation/content/1.x/6-validation-rules/03-alpha.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
title: Alpha
description: "Validate that a value contains only alphabetic characters."
---

## Overview

This rule validates whether a given string value contains only alphabetic characters (A-Z, a-z).

## Example

```php
use Tempest\Validation\Rules\Alpha;

final class User
{
#[Alpha()]
public string $username;
}
```

## See also

- [Tempest\Validation\Rules\AlphaNumeric](04-alpha-numeric.md)
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
title: AlphaNumeric
description: "Validate that a value contains only alphanumeric characters."
---

## Overview

This rule validates whether a given string value contains only alphanumeric characters (A-Z, a-z, 0-9).

## Example

```php
use Tempest\Validation\Rules\AlphaNumeric;

final class User
{
#[AlphaNumeric()]
public string $username;
}
```

## See also

- [Tempest\Validation\Rules\Alpha](03-alpha.md)
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
title: ArrayList
description: "Validate that a value is an array list."
---

## Overview

This rule validates whether a given value is an array list (a non-associative array).

## Example

```php
use Tempest\Validation\Rules\ArrayList;

final class Post
{
#[ArrayList]
public array $tags;
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
title: BeforeDate
description: "Validate that a date is before a specific date."
---

## Overview

This rule validates whether a given date value is before a specified date. You can also choose to include the specified date in the validation.

## Parameters

- `$date` (`DateTimeInterface|DateTimeImmutable|string`): The date to compare against. Defaults to `now`.
- `$inclusive` (`bool`): Whether to include the specified date in the validation. Defaults to `false`.

## Examples

### Before a specific date

```php
use Tempest\Validation\Rules\BeforeDate;
use Tempest\DateTime\DateTime;

final class Book
{
#[BeforeDate('2023-01-01')]
public DateTime $fooDate;

#[BeforeDate(new DateTime('2023-01-01'))]
public DateTime $barDate;

#[BeforeDate(new DateTimeImmutable('2023-01-01'))]
public DateTime $bazDate;
}
```

### Before a specific date (inclusive)

```php
use Tempest\Validation\Rules\BeforeDate;

final class Book
{
#[BeforeDate('2023-01-01', inclusive: true)]
public DateTime $fooDate;

#[BeforeDate(new DateTime('2023-01-01'), inclusive: true)]
public DateTime $barDate;

#[BeforeDate(new DateTimeImmutable('2023-01-01'), inclusive: true)]
public DateTime $bazDate;
}
```

## See also

- [Tempest\Validation\Rules\AfterDate](02-after-date.md)
- [Tempest\Validation\Rules\BetweenDates](08-between-dates.md)
30 changes: 30 additions & 0 deletions src/Web/Documentation/content/1.x/6-validation-rules/07-between.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
title: Between
description: "Validate that a value is between a minimum and maximum value."
---

## Overview

This rule validates whether a given numeric value is between a specified minimum and maximum value (inclusive).

## Parameters

- `$min` (`int`): The minimum allowed value.
- `$max` (`int`): The maximum allowed value.

## Example

```php
use Tempest\Validation\Rules\Between;

final class Product
{
#[Between(min: 1, max: 100)]
public int $stock;
}
```

## See also

- [Tempest\Validation\Rules\Count](09-count.md)
- [Tempest\Validation\Rules\Length](28-length.md)
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
title: BetweenDates
description: "Validate that a date is between two other dates."
---

## Overview

This rule validates whether a given date value is between two other dates. You can specify whether the start and end dates should be included in the validation.

## Parameters

- `$first` (`DateTimeInterface|DateTimeImmutable|string`): The first date.
- `$second` (`DateTimeInterface|DateTimeImmutable|string`): The second date.
- `$inclusive` (`bool`): Whether to include the start and end dates in the validation. Defaults to `false`.

## Examples

### Between two dates (exclusive)

```php
use DateTimeImmutable;
use Tempest\Validation\Rules\BetweenDates;
use Tempest\DateTime\DateTime;
final class Event
{
#[BetweenDates('2023-01-01', '2023-12-31')]
public DateTime $fooDate;

#[BetweenDates(new DateTime('2023-01-01'), new DateTime('2023-12-31'))]
public DateTime $barDate;

#[BetweenDates(new DateTimeImmutable('2023-01-01'), new DateTimeImmutable('2023-12-31'))]
public DateTime $bazDate;
}
```

### Between two dates (inclusive)

```php
use Tempest\Validation\Rules\BetweenDates;

final class Event
{
#[BetweenDates('2023-01-01', '2023-12-31', inclusive: true)]
public DateTime $fooDate;

#[BetweenDates(new DateTime('2023-01-01'), new DateTime('2023-12-31'), inclusive: true)]
public DateTime $barDate;

#[BetweenDates(new DateTimeImmutable('2023-01-01'), new DateTimeImmutable('2023-12-31'), inclusive: true)]
public DateTime $bazDate;
}
```

## See also

- [Tempest\Validation\Rules\AfterDate](02-after-date.md)
- [Tempest\Validation\Rules\BeforeDate](06-before-date.md)
Loading
Loading