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 request: Validate leading zero for numericality #106

Closed
mondwan opened this Issue Mar 24, 2016 · 5 comments

Comments

Projects
None yet
3 participants
@mondwan
Contributor

mondwan commented Mar 24, 2016

Goal:

  • Expect "010" to be false in numericality validator

Description:

It will be great if there is an option like noLeadingZero in numericality.

Why

  • Value from HTML5 number box is string
  • The coercion of + will force "010" to be 10

Facts above make 010 to be a valid number which it should not be in reality in my opinion.

JS:

var c = {
    "numericality": {
    "greaterThanOrEqualTo":1,
    "lessThanOrEqualTo":100,
    "message":"<id> from 1 to 100",
  },
  "presence": true,
};

// Expect to be false, but get true
console.log(
    'validation result ',
    validate.single('010', c)
);

// No problem
console.log(
    'validation result ',
    validate.single('10', c)
);

Fiddler:

https://jsfiddle.net/8okbtbuz/2/

mondwan added a commit to mondwan/validate.js that referenced this issue Mar 24, 2016

@ansman

This comment has been minimized.

Show comment
Hide comment
@ansman

ansman Apr 5, 2016

Owner

Agreed, though I think the option should be called strict instead.

Owner

ansman commented Apr 5, 2016

Agreed, though I think the option should be called strict instead.

@xhh2a

This comment has been minimized.

Show comment
Hide comment
@xhh2a

xhh2a Apr 9, 2016

Please make this an option, I would like cases where it is the current behavior.

xhh2a commented Apr 9, 2016

Please make this an option, I would like cases where it is the current behavior.

@mondwan

This comment has been minimized.

Show comment
Hide comment
@mondwan

mondwan Apr 9, 2016

Contributor

This option is optional by default

Contributor

mondwan commented Apr 9, 2016

This option is optional by default

@mondwan

This comment has been minimized.

Show comment
Hide comment
@mondwan

mondwan Apr 9, 2016

Contributor

By the way, option has been renamed to strict as requested in the pull request. However, I am not sure how to deal with floating point number. Should I allow all trailing zero if that is a float?

If yes, I can simply add a check and bypass this checking.

Contributor

mondwan commented Apr 9, 2016

By the way, option has been renamed to strict as requested in the pull request. However, I am not sure how to deal with floating point number. Should I allow all trailing zero if that is a float?

If yes, I can simply add a check and bypass this checking.

@ansman ansman closed this in 578426d Apr 17, 2016

@ansman

This comment has been minimized.

Show comment
Hide comment
@ansman

ansman May 20, 2016

Owner

This is now released in 0.10.0

Owner

ansman commented May 20, 2016

This is now released in 0.10.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment