validating 0x prefixed hex
How can I validate a hex string that is prefixed by
0x<hex>
in typescript...
Can I do this same thing here?6 Replies
In zod I would
but that never passed through to
0x...
in typescript landYou can use a regex literal:
https://arktype.io/docs/primitives#string-patterns
You can also use the builtin
string.hex
keyword.
If you want narrowed type inference, you will have to use .as<
0x${string}>()
at least until I publish 2.2 which includes regex inference 😊but the regex makes sense


I like this better