cjbeck71081 Posted September 17, 2008 Share Posted September 17, 2008 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? Quote Link to comment Share on other sites More sharing options...
Psycho Posted September 17, 2008 Share Posted September 17, 2008 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, '') Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted September 17, 2008 Share Posted September 17, 2008 That's Javascript, not PHP. This is a PHP forum. Ken Quote Link to comment Share on other sites More sharing options...
Psycho Posted September 17, 2008 Share Posted September 17, 2008 Oh, hell, my mistake. Pretty similar solution though: PHP Version $input = "6050 SQFT"; $output = preg_replace('/[^0-9\.]/', '', $input); echo $output; //6050 Quote Link to comment Share on other sites More sharing options...
DarkWater Posted September 17, 2008 Share Posted September 17, 2008 . loses its metacharacter meaning inside of a class. =P You don't need to escape it. #Regex /[^0-9.]/ Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.