Jump to content

Quick Question: How do I strip all alphabetical characters out of a string


cjbeck71081

Recommended Posts

I have a property listing service and I want people to put in the number of square feet for a proerpty, and i want to take thier value and take all the letters out of it, incase they put in 6050 SQFT, or 5405 sf or 34534 s.f., etc.

 

Any ideas?

var sqrFt = "6050 SQFT";
alert(sqrFt.replace(/[a-z ]/gi, '')); //Output = '6050'

 

Although, if you ONLY want numbers then you would use something like this

sqrFt.replace(/[^0-9]/g, '')

 

Or this if you want to allow a decimal (however you would need an additional step to ensure there are not two decimals)

sqrFt.replace(/[^0-9\.]/g, '')

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.