Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: String starts/ends with #604

Closed
alii opened this issue Aug 23, 2021 · 4 comments
Closed

Feature: String starts/ends with #604

alii opened this issue Aug 23, 2021 · 4 comments
Labels
wontfix This will not be worked on

Comments

@alii
Copy link
Sponsor Contributor

alii commented Aug 23, 2021

I was writing a validator for a hex color code and thought that being able to check that it started with a # would be a nice addition.

E.g.: z.string().length(7).startsWith('#')

@DASPRiD
Copy link
Contributor

DASPRiD commented Aug 25, 2021

You can already do that:

z.string().length(7).regex(/^#/);

@colinhacks
Copy link
Owner

Even though this is doable with regexes, it's also a one-line addition to ZodString so I'm fine adding it into core. PR welcome 👍

This was referenced Jan 28, 2022
@stale
Copy link

stale bot commented Mar 2, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix This will not be worked on label Mar 2, 2022
@stale stale bot closed this as completed Mar 9, 2022
@agustif
Copy link

agustif commented Apr 25, 2022

An updated version if you need supporting 3 and 8 digit hex too

color: z.string().min(4).max(9).regex(/^#/),
This allows for
#FFF (White, simplified, it just becomes #FFFFFF)
and #FFFFFF80 (White, with 80% transparency)

in case helps anyone looking for this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

4 participants