Skip to content

Commit

Permalink
Merge branch 'main' into feat/use-interface-for-base-types
Browse files Browse the repository at this point in the history
  • Loading branch information
Saeris committed Jan 18, 2024
2 parents c2dc365 + 671f3ea commit 527a05c
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 1 deletion.
19 changes: 19 additions & 0 deletions website/src/routes/api/(types)/EmailValidation/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
title: EmailValidation
description: Email validation type.
contributors:
- fabian-hiller
---

import { Property } from '~/components';
import { properties } from './properties';

# EmailValidation

Email validation type.

## Definition

- `EmailValidation` <Property {...properties.BaseValidation} />
- `type` <Property {...properties.type} />
- `requirement` <Property {...properties.requirement} />
31 changes: 31 additions & 0 deletions website/src/routes/api/(types)/EmailValidation/properties.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import type { PropertyProps } from '~/components';

export const properties: Record<string, PropertyProps> = {
BaseValidation: {
type: [
{
type: 'custom',
name: 'BaseValidation',
href: '../BaseValidation/',
generics: [
{
type: 'custom',
name: 'TInput',
},
],
},
],
},
type: {
type: {
type: 'string',
value: 'email',
},
},
requirement: {
type: {
type: 'custom',
name: 'RegExp',
},
},
};
50 changes: 49 additions & 1 deletion website/src/routes/api/(validations)/email/index.mdx
Original file line number Diff line number Diff line change
@@ -1,10 +1,58 @@
---
title: email
description: Creates a pipeline validation action that validates an email.
source: /validations/email/email.ts
contributors:
- fabian-hiller
---

import { ApiList, Property } from '~/components';
import { properties } from './properties';

# email

> The content of this page is not yet ready. Until then, please use the [source code](https://github.com/fabian-hiller/valibot/blob/main/library/src/validations/email/email.ts) or take a look at [issue #287](https://github.com/fabian-hiller/valibot/issues/287) to help us extend the API reference.
Creates a pipeline validation action that validates an email.

```ts
const Validation = email<TInput>(message);
```

## Generics

- `TInput` <Property {...properties.TInput} />

## Parameters

- `message` <Property {...properties.message} />

### Explanation

With `email` you can validate the formatting of a string. If the input is not an email, you can use `message` to customize the error message.

## Returns

- `Validation` <Property {...properties.Validation} />

## Examples

The following examples show how `email` can be used.

### Email schema

Schema to validate an email.

```ts
const EmailSchema = string([
minLength(1, 'Please enter your email.'),
email('The email is badly formatted.'),
maxLength(30, 'Your email is too long.'),
]);
```

## Related

The following APIs can be combined with `email`.

### Schemas

<ApiList items={['any', 'string', 'unknown']} />
30 changes: 30 additions & 0 deletions website/src/routes/api/(validations)/email/properties.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import type { PropertyProps } from '~/components';

export const properties: Record<string, PropertyProps> = {
TInput: {
type: 'string',
},
message: {
type: [
{
type: 'custom',
name: 'ErrorMessage',
href: '../ErrorMessage/',
},
'undefined',
],
default: {
type: 'string',
value: 'Invalid email',
},
},
Validation: {
type: [
{
type: 'custom',
name: 'EmailValidation',
href: '../EmailValidation/',
},
],
},
};
1 change: 1 addition & 0 deletions website/src/routes/api/menu.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@
- [BooleanSchema](/api/BooleanSchema/)
- [Class](/api/Class/)
- [DateSchema](/api/DateSchema/)
- [EmailValidation](/api/EmailValidation/)
- [Enum](/api/Enum/)
- [EnumSchema](/api/EnumSchema/)
- [ErrorMessage](/api/ErrorMessage/)
Expand Down

0 comments on commit 527a05c

Please sign in to comment.