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? Link to comment https://forums.phpfreaks.com/topic/124638-quick-question-how-do-i-strip-all-alphabetical-characters-out-of-a-string/ 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, '') Link to comment https://forums.phpfreaks.com/topic/124638-quick-question-how-do-i-strip-all-alphabetical-characters-out-of-a-string/#findComment-643719 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 Link to comment https://forums.phpfreaks.com/topic/124638-quick-question-how-do-i-strip-all-alphabetical-characters-out-of-a-string/#findComment-643726 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 Link to comment https://forums.phpfreaks.com/topic/124638-quick-question-how-do-i-strip-all-alphabetical-characters-out-of-a-string/#findComment-644178 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.]/ Link to comment https://forums.phpfreaks.com/topic/124638-quick-question-how-do-i-strip-all-alphabetical-characters-out-of-a-string/#findComment-644181 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.