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

Does IsDecimal do what it should do? #1423

Closed
kaytrance opened this issue Nov 25, 2021 · 5 comments
Closed

Does IsDecimal do what it should do? #1423

kaytrance opened this issue Nov 25, 2021 · 5 comments
Labels
type: question Questions about the usage of the library.

Comments

@kaytrance
Copy link

Why IsDecimal() decorator description says that "Checks if the string contains only letters and numbers. If given value is not a string, then it returns false." and it does not check of the value was decimal or not?

While isDecimal() contains proper description and probably does that it means.

For example @IsDecimal on a field with value 123.45 passes validation while it should not, imo.

import { ValidationOptions } from '../ValidationOptions';
import ValidatorJS from 'validator';
export declare const IS_DECIMAL = "isDecimal";
/**
 * Checks if the string is a valid decimal.
 * If given value is not a string, then it returns false.
 */
export declare function isDecimal(value: unknown, options?: ValidatorJS.IsDecimalOptions): boolean;
/**
 * Checks if the string contains only letters and numbers.
 * If given value is not a string, then it returns false.
 */
export declare function IsDecimal(options?: ValidatorJS.IsDecimalOptions, validationOptions?: ValidationOptions): PropertyDecorator;
@kaytrance kaytrance added the type: question Questions about the usage of the library. label Nov 25, 2021
@x4th
Copy link

x4th commented Jan 14, 2022

Why do you think 123.45 shouldn’t pass validation?

@x4th
Copy link

x4th commented Jan 20, 2022

Under the hood this libarary uses validator, on their page, in this table you can see details about isDecimal.

@braaar
Copy link
Member

braaar commented Jan 20, 2022

It seems like the docstring for IsAlphanumeric has been copied over to IsDecimal

@kaytrance, judging by your description you probably want to use IsAlphanumeric for your use case.

https://github.com/typestack/class-validator/blob/develop/src/decorator/string/IsAlphanumeric.ts

/**
 * Checks if the string contains only letters and numbers.
 * If given value is not a string, then it returns false.
 */
export function isAlphanumeric(value: unknown, locale?: ValidatorJS.AlphanumericLocale): boolean {
  return typeof value === 'string' && isAlphanumericValidator(value, locale);
}

We need to update the docstring for IsDecimal

@NoNameProvided
Copy link
Member

As @braaar said, the JSDOC was incorrect. It has been updated in 42b9ca2.

Closing as solved.

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: question Questions about the usage of the library.
Development

Successfully merging a pull request may close this issue.

4 participants