You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can validate each fields passing either `regex` or `validate` to any field that support it. Not all field supports `regex` for instance but all fields support `validate`.
101
+
In addition many field support `required`, `minLength`, `maxLength`, `min`, and `max` validation.
102
+
103
+
#### Native Validation
104
+
105
+
```tsx
106
+
<TextInputField
107
+
name="firstName"
108
+
required
109
+
minLength={2}
110
+
maxLength={30}
111
+
/>
112
+
```
113
+
114
+
#### With Validate
115
+
116
+
```tsx
117
+
const EXISTING_IPS = ['192.168.1.1']
118
+
119
+
<TextInputField
120
+
name="ip"
121
+
validate={{
122
+
ipAlreadyExists: (ip:string) =>
123
+
EXISTING_IPS.includes(ip) ?'This ip is already in use':undefined,
We all know regex can be tricky, so to help you with that we made [Scaleway Regex](https://github.com/scaleway/scaleway-lib/tree/main/packages/regex) library that contains a lot of useful regexes that you can use in your forms.
138
+
You can easily install it with:
139
+
140
+
```sh
141
+
pnpm add @scaleway/regex
142
+
```
143
+
144
+
You can then use it like this:
145
+
146
+
```tsx
147
+
import { email } from'@scaleway/regex'
148
+
149
+
<TextInputField
150
+
name="email"
151
+
regex={[email]}
152
+
/>
153
+
```
154
+
155
+
Check all the available regexes in the [Scaleway Regex file](https://github.com/scaleway/scaleway-lib/blob/main/packages/regex/src/index.ts)
156
+
157
+
### Resolvers | Zod
158
+
159
+
You can use [Zod](https://zod.dev/) for validation by integrating it with `@ultraviolet/form`. First you will need to install Zod and the Zod resolver for React Hook Form:
If you need more examples with other resolvers we invite you to check [React Hook Form Resolvers Documentation](https://github.com/react-hook-form/resolvers#quickstart)
0 commit comments