-
-
Notifications
You must be signed in to change notification settings - Fork 225
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
Add export for any validation regex #219
Conversation
✅ Deploy Preview for valibot canceled.
|
Co-authored-by: Jacob Groß <[email protected]>
3083d46
to
a6f405c
Compare
@@ -7,7 +12,7 @@ | |||
*/ | |||
export function isLuhnAlgo(input: string) { | |||
// Remove any non-digit chars | |||
const number = input.replace(/\D/gu, ''); | |||
const number = input.replace(NON_DIGIT_REGEX, ''); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs replaceAll
here (could be automatically captured by https://github.com/fabian-hiller/valibot/pull/213/files unicorn/prefer-string-replace-all
I think.
reason is: a global regex (/g
) will set lastIndex
to the last index where the regex stopped. Which means if string a is "abc1" and string b is "a", lastIndex will be set to e.g. 3, but string b has no index 3, so the regex now fails at all times.
If you want to avoid replaceAll
, you'll need to call
NON_DIGIT_REGEX.lastIndex = 0
before calling the replace
* [IPv4](https://en.wikipedia.org/wiki/IPv4) regex. | ||
*/ | ||
// eslint-disable-next-line redos-detector/no-unsafe-regex -- false positive | ||
export const IPV4_REGEX = /^(?:(?:25[0-5]|(?:2[0-4]|1\d|[1-9])?\d)\.?\b){4}$/u; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export const IPV4_REGEX = /^(?:(?:25[0-5]|(?:2[0-4]|1\d|[1-9])?\d)\.?\b){4}$/u; | |
export const IPV4_REGEX = /^(?:25[0-5]|(?:2[0-4]|1\d|[1-9]|)\d)(?:\.(?:25[0-5]|(?:2[0-4]|1\d|[1-9]|)\d)){3}$/u; |
v0.20.0 is now available |
No description provided.