DT
Drizzle Team•10mo ago
textYash

How to check schema fields against a regex?

I want to restrict the usernames in my user table with a regex. Basically instagram like criteria for usernames. This is my current schema:
username: varchar('username', { length: 128 }).unique().notNull(),
username: varchar('username', { length: 128 }).unique().notNull(),
Is there any method that I can call on this to restrict the username? Something like this:
username: varchar('username', { length: 64 }).unique().notNull()./^(?!.*\.\.)(?!.*\.$)[^\W][\w.]{0,64}$/igm.test(email),
username: varchar('username', { length: 64 }).unique().notNull()./^(?!.*\.\.)(?!.*\.$)[^\W][\w.]{0,64}$/igm.test(email),
I know that's nonsense code above, but I'm just trying to convey myself. please don't mind 😅
2 Replies
petsagouris
petsagouris•10mo ago
I think you would be better off with a validation library like zod.
textYash
textYashOP•10mo ago
Okay
Want results from more Discord servers?
Add your server