Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / ColdFusion / Getting Started / May 2006



Tip: Looking for answers? Try searching our database.

Javascript Question Remove Leading zero's

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
umuayo - 24 May 2006 17:27 GMT
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
Dan Bracuk - 24 May 2006 18:12 GMT
<blockquote>quote:<br><hr><i>Originally posted by: <b><b>jdeline</b></b></i>
Multiply by one removes the leading zeros.  <CFSET foo = 1 * userData)>  Be
sure to do this <i>after</i> you verify that userData is
numeric.<hr></blockquote>
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.
amadeusmax - 27 May 2006 22:20 GMT
I am going out on limb here and assuming that your looking at a string. The
solution would be convert to a number

parseFloat('00785')
which would make 785

>I have a hidden Input form that has a value of 78, I am using javascript to
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.