l0ve2hat3 Posted December 17, 2009 Share Posted December 17, 2009 I need help replacing any non numeric numbers besides a decimal. so basically the user will either be typing in a float or an integer. Can someone help me with the regex part of preg_replace? Link to comment https://forums.phpfreaks.com/topic/185498-preg-replace-non-numeric/ Share on other sites More sharing options...
JAY6390 Posted December 17, 2009 Share Posted December 17, 2009 $output = preg_replace('/[^\d\.]/','',$input); if(!preg_match('/^\d+(\.d+)?$/', $output)) { //Invalid number code here }else{ //valid number code here } Link to comment https://forums.phpfreaks.com/topic/185498-preg-replace-non-numeric/#findComment-979362 Share on other sites More sharing options...
l0ve2hat3 Posted December 17, 2009 Author Share Posted December 17, 2009 thank you Link to comment https://forums.phpfreaks.com/topic/185498-preg-replace-non-numeric/#findComment-979371 Share on other sites More sharing options...
JAY6390 Posted December 17, 2009 Share Posted December 17, 2009 No problem Link to comment https://forums.phpfreaks.com/topic/185498-preg-replace-non-numeric/#findComment-979377 Share on other sites More sharing options...
nrg_alpha Posted December 17, 2009 Share Posted December 17, 2009 Jay, you don't need to escape the dot in your character class.. most meta characters loose their special meaning within the class.. the dot is one of those characters that do.. so [^\d.] would also work (no harm in escaping them otherwise, but not necessary). Link to comment https://forums.phpfreaks.com/topic/185498-preg-replace-non-numeric/#findComment-979400 Share on other sites More sharing options...
JAY6390 Posted December 17, 2009 Share Posted December 17, 2009 Yeah I do it just out of habit lol Link to comment https://forums.phpfreaks.com/topic/185498-preg-replace-non-numeric/#findComment-979403 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.