Signup form validation

I'm building a sign up form that looks like this:
const schema = type({
email: 'email',
password: 'string>1',
confirmPassowrd: 'string'
})
const schema = type({
email: 'email',
password: 'string>1',
confirmPassowrd: 'string'
})
How can I validate the confirmPassword field and make sure it is equal "===" to the password field? SOLUTION: https://discord.com/channels/957797212103016458/1117525551079501917/1117532686299435038
32 Replies
TizzySaurus
TizzySaurus2y ago
Have you tried string===password?
Gabriel Silva
Gabriel SilvaOP2y ago
no I haven't i'll try it out and let you know how it goes
TizzySaurus
TizzySaurus2y ago
Oh, that's not a scope you're using
Gabriel Silva
Gabriel SilvaOP2y ago
no should i?
Type '"string===password"' is not assignable to type '"Comparator == must be followed by a number literal (was '')"'
Type '"string===password"' is not assignable to type '"Comparator == must be followed by a number literal (was '')"'
TizzySaurus
TizzySaurus2y ago
I'm not sure that it's [directly] possible in the current version Iirc there's a .equals() or something in beta
Gabriel Silva
Gabriel SilvaOP2y ago
hmm
Dimava
Dimava2y ago
const schema = type({
email: 'email',
password: 'string>1',
confirmPassowrd: 'string'
}).narrow((data, problems) => {
if (data.password != data.confirmPassowrd)
problems.mustBe('same as password', ['confirmPassowrd'])
})
const schema = type({
email: 'email',
password: 'string>1',
confirmPassowrd: 'string'
}).narrow((data, problems) => {
if (data.password != data.confirmPassowrd)
problems.mustBe('same as password', ['confirmPassowrd'])
})
TizzySaurus
TizzySaurus2y ago
Morphs are probably the way to go, yeah
Dimava
Dimava2y ago
narrow not morph
TizzySaurus
TizzySaurus2y ago
Then you can also add more validation to password, like "must have at least one number" or whatever Hmm, I suppose... not sure there's a difference though
Dimava
Dimava2y ago
morph is mutating so has different IO
TizzySaurus
TizzySaurus2y ago
Eh, I guess But they can be the same if you code it to be so
Dimava
Dimava2y ago
so it makes Type<string> vs Type<(in:string) => string> you can't ^
TizzySaurus
TizzySaurus2y ago
Not that it practically matters though The validation applied will be the same
Gabriel Silva
Gabriel SilvaOP2y ago
thats nice, thanks a lot
Dimava
Dimava2y ago
It will later
TizzySaurus
TizzySaurus2y ago
Fair enough
Dimava
Dimava2y ago
e.g morphs gonna support clone-before-morph or something
Gabriel Silva
Gabriel SilvaOP2y ago
totally unrelated, is there an ETA for the next release?
Dimava
Dimava2y ago
thirthday
Gabriel Silva
Gabriel SilvaOP2y ago
been trying out arktype lately and really enjoying
TizzySaurus
TizzySaurus2y ago
#announcements :)
Gabriel Silva
Gabriel SilvaOP2y ago
thanks 🙏 is there a way to mark something as the answer here?
Gabriel Silva
Gabriel SilvaOP2y ago
done
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Dimava
Dimava2y ago
I would say
const schema = narrow({
email: 'email',
password: 'string>1',
confirmPassowrd: 'string'
}, (data, problems) => {
if (data.password != data.confirmPassowrd)
problems.mustBe('same as password', {path: ['confirmPassowrd']})
return data.password === data.confirmPassowrd
})
const schema = narrow({
email: 'email',
password: 'string>1',
confirmPassowrd: 'string'
}, (data, problems) => {
if (data.password != data.confirmPassowrd)
problems.mustBe('same as password', {path: ['confirmPassowrd']})
return data.password === data.confirmPassowrd
})
but well
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Dimava
Dimava2y ago
My boat was lazy to actualy write in editor so thanks for correct impl
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
ssalbdivad
ssalbdivad2y ago
Also note that there is an issue in the backlog to make this easier (not described yet but you get the high level idea from the title : P): https://github.com/arktypeio/arktype/issues/485
Gabriel Silva
Gabriel SilvaOP2y ago
thats great news

Did you find this page helpful?