Making a column only allow letters and characters, including capitals

I am using Yup for my validation on the client side. For example the username field does this:
.matches(/^[a-zA-Z0-9]*$/, 'Username can only contain letters and numbers')
.matches(/^[a-zA-Z0-9]*$/, 'Username can only contain letters and numbers')
My user schema on the drizzle side is:
username: varchar('username', { length: 20 }).unique().notNull(),
username: varchar('username', { length: 20 }).unique().notNull(),
Just wondering is there a way to add the regex to it? Thanks
2 Replies
Luxaritas
Luxaritas16mo ago
You could potentially use a CHECK constraint if you want it validated on a database level, though that's not currently implemented in drizzle directly If you're just looking for serverside validation though, typically you'd do that before you even make a request to your database (some frameworks provide a built-in way to do request validation, or you may chose to use zod or similar)
cobite
cobiteOP16mo ago
Yeah i'm just validating it on the backend via yup, was just wondering if I could do it on the database side also. Thanks
Want results from more Discord servers?
Add your server