Comments (2)
Update: Previously, check
was not executed if the email field was untyped. This problem can now be solved with our new partialCheck
action.
import * as v from 'valibot';
const RegisterSchema = v.pipe(
v.object({
email: v.pipe(
v.string(),
v.nonEmpty('Please enter your email.'),
v.email('The email address is badly formatted.'),
),
password1: v.pipe(
v.string(),
v.nonEmpty('Please enter your password.'),
v.minLength(8, 'Your password must have 8 characters or more.'),
),
password2: v.string(),
}),
v.forward(
v.partialCheck(
[['password1'], ['password2']],
(input) => input.password1 === input.password2,
'The two passwords do not match.',
),
['password2'],
),
);
from valibot.
The official recommendation is to use the check
action together with the forward
method. This week or next I will also work on a partialCheck
and refine
action (issue #597) that will help cover more advanced cases.
import * as v from 'valibot';
const RegisterSchema = v.pipe(
v.object({
email: v.pipe(
v.string(),
v.nonEmpty('Please enter your email.'),
v.email('The email address is badly formatted.')
),
password1: v.pipe(
v.string(),
v.nonEmpty('Please enter your password.'),
v.minLength(8, 'Your password must have 8 characters or more.')
),
password2: v.string(),
}),
v.forward(
v.check(
(input) => input.password1 === input.password2,
'The two passwords do not match.'
),
['password2']
)
);
from valibot.
Related Issues (20)
- Add TypeScript types to documentation using TwoSlash HOT 1
- Attempted import error: 'getDotPath' is not exported fom 'validbot' (imported as 'o') HOT 3
- Typesafe introspection HOT 1
- Support for String normalization HOT 2
- Add validation action to validate JWT
- Type of ValiError.issues HOT 6
- Property 'key' does not exist on type 'IssuePathItem' HOT 2
- Provide source locations for errors in string data HOT 6
- Empty email field validation HOT 1
- Empty object type returned by flattening a Variant Schema HOT 4
- Unable to use partial() with SchemaWithPipe HOT 2
- Improve DX with `babel-plugin-transform-regex` HOT 6
- TS2589: Type instantiation is excessively deep and possibly infinite using forward and check HOT 2
- Shorthand for transforming `null` to `undefined` HOT 1
- How to pass down original input for use in config message HOT 5
- Validation for multiple possible values or notValues HOT 4
- Codemod with `toTrimmed` fails HOT 2
- Complex error messages using enums HOT 9
- Error: 'pipe' not found in imported namespace 'v' HOT 3
- issue - recursive schema seems to produce incomplete Issues HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from valibot.