react-hook-form: How to force lowercase characters

I want to accept a username that only consists of lowercase characters
Solution:
watch('field') to listen to changes
Jump to solution
8 Replies
Neto
Neto•8mo ago
GitHub
TypeScript-first schema validation with static type inference
TypeScript-first schema validation with static type inference
Neto
Neto•8mo ago
const myString = z.string().refine((val) => val === val.toLowerCase(), {
message: "..."
});
const myString = z.string().refine((val) => val === val.toLowerCase(), {
message: "..."
});
FleetAdmiralJakob 🗕 🗗 🗙
hi, thank you, but wouldn't it be nicer if every character you type into the input is automatically the lowercase version?
Neto
Neto•8mo ago
also works, i was just giving a solution you can use rhf with watch, a effect, getValue, and setValue
FleetAdmiralJakob 🗕 🗗 🗙
ohh that's nice thank you
Solution
Neto
Neto•8mo ago
watch('field') to listen to changes
Neto
Neto•8mo ago
in a effect to run getValue to get the current value setValue as the value with lowercase stuff
FleetAdmiralJakob 🗕 🗗 🗙
thank you, I will try it out
Want results from more Discord servers?
Add your server