client_side_validations icon indicating copy to clipboard operation
client_side_validations copied to clipboard

leading/trailing spaces trip up validation

Open kellerapps opened this issue 14 years ago • 3 comments

At least it does for numericality.

kellerapps avatar Feb 04 '12 00:02 kellerapps

The numericality validator uses parseInt to extract the integer and the following works with trailing whitespace:

parseInt("   1234    ")
> 1234

So a few questions to help diagnose your issue:

  1. What browser/version are you using?
  2. What does the model validation look like?

bcardarella avatar Feb 04 '12 01:02 bcardarella

  1. chrome 16.0.912.75 m on Win7
  2. validates :answer, :presence => true, :numericality => { :only_integer => true }

On Fri, Feb 3, 2012 at 5:35 PM, Brian Cardarella < [email protected]

wrote:

The numericality validator uses parseInt to extract the integer and the following works with trailing whitespace:

parseInt("   1234    ")
> 1234

So a few questions to help diagnose your issue:

  1. What browser/version are you using?
  2. What does the model validation look like?

Reply to this email directly or view it on GitHub:

https://github.com/bcardarella/client_side_validations/issues/268#issuecomment-3807402

kellerapps avatar Feb 04 '12 02:02 kellerapps

Ah, yup that's a bug. For :only_integer we are doing a regular expression match. Thank-you. I'll fix in master.

bcardarella avatar Feb 04 '12 02:02 bcardarella