Skip to main content
Inspiring
May 24, 2006
Question

Javascript Question Remove Leading zero's

  • May 24, 2006
  • 1 reply
  • 1708 views
I have a hidden Input form that has a value of 78, I am using javascript to validate that the amount the User entered in a new Input form is greater than the amount in the hidden form. But this is failing when a user enters stuff like 0775 or 000745. Is there a way I could remove the leading o's zeros and then do the validation. <cfinput validate integer> allows entering of leading zeros, I want to remove the leading zeros. Is it possible?

Thanks
This topic has been closed for replies.

1 reply

May 24, 2006
Multiply by one removes the leading zeros. <CFSET foo = 1 * userData)> Be sure to do this after you verify that userData is numeric.
Inspiring
May 24, 2006
quote:

Originally posted by: jdeline
Multiply by one removes the leading zeros. <CFSET foo = 1 * userData)> Be sure to do this after you verify that userData is numeric.

Regarding ensuring the value is numeric, be careful of using the js parseint, parsefloat or whatever those functions are called. They don't always return NaN (not a number) for non-numeric strings.