Thanks for the tips, Brian! That gave me just the insight I needed.
Here's what I finally ended up with: if ( isNaN (this.value.replace(/\$|,|\./g,''))) That disregards any $ or , or . (commonly used US dollar symbols) to tell me if what is left is a number, which I can parse and store in my database as numeric. I didn't understand the | as "or". Also, what is the g for? Rick > -----Original Message----- > From: jquery-en@googlegroups.com [mailto:jquery...@googlegroups.com] On > Behalf Of brian > Sent: Saturday, January 03, 2009 1:43 PM > To: jquery-en@googlegroups.com > Subject: [jQuery] Re: Why would this code not allow a $ as part of the input? > > > On Sat, Jan 3, 2009 at 12:26 PM, Rick Faircloth > <r...@whitestonemedia.com> wrote: > > > > Hi, all... > > > > I'm writing some validation code and have an input > > for dollar amounts and would like for users to be able to > > enter digits or $ or , or . all of which are commonly > > used in US dollar values. > > > > The code I've written should verify that after any $ or , or . > > are removed from a user's entry, there is only digits remaining. > > > > However, when I enter either $ or , or . into the string, > > the string is rejected as valid. > > > > $1200 doesn't even pass. > > > > Is there something wrong with my code or logic? > > > > Thanks for any feedback, > > > > Rick > > > > Here's the code: > > > > $(':input.number').each(function() { > > $(this).blur(function() { > > if ( isNaN (this.value.replace(/[\$\,\./,""]/))) > > { $('#' + this.id + '_number_error').fadeIn(500); > > $('#submit').attr('disabled', 'disabled'); } > > else > > { $('#' + this.id + '_number_error').fadeOut(250); > > $('#submit').removeAttr('disabled'); }; > > }); > > }); > > > > > > You're trying to remove the decimal place, among other things. That's > probably not what you want. This will remove any dollar signs or > commas, then check the result is a float: > > $(':input.number').each(function() > { > $(this).blur(function() > { > var value = parseFloat($(this).val().replace(/\$|,/g,'')); > > if (isNaN(value)) > { > alert('no good'); > } > else > { > alert('ok: ' + value); > }; > }); > });