Skip to content
This repository was archived by the owner on Dec 12, 2021. It is now read-only.
This repository was archived by the owner on Dec 12, 2021. It is now read-only.

Feature request: Validate leading zero for numericality #106

@mondwan

Description

@mondwan

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/

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions