Tenaciousmug Posted May 12, 2011 Share Posted May 12, 2011 I can't ever get this stupid function to work. I do it all the time and try to find other ways around it because I can never get ANY of mine to work. And then I go to boards and copy theirs to see if they work and they don't.... so I really don't get what I'm doing wrong. $depositamt = $_POST['depositamt']; if (!preg_match("^[0-9]+$", $depositamt)) This is what I have. Well not the whole code, but you get what I'm doing... Quote Link to comment https://forums.phpfreaks.com/topic/236271-preg_match-never-working/ Share on other sites More sharing options...
requinix Posted May 12, 2011 Share Posted May 12, 2011 PCRE expressions need delimiters. '/^[0-9]+$/' Also, if (strlen($depositamt) == 0 || !ctype_digit($depositamt)) { Quote Link to comment https://forums.phpfreaks.com/topic/236271-preg_match-never-working/#findComment-1214743 Share on other sites More sharing options...
Tenaciousmug Posted May 12, 2011 Author Share Posted May 12, 2011 Is that another way of doing it? I really rather stick with the preg_match since I'm more familiar with it doing characters. Is there any way to do this with preg_match? And it does have an ending delimiter. That's the $... Quote Link to comment https://forums.phpfreaks.com/topic/236271-preg_match-never-working/#findComment-1214745 Share on other sites More sharing options...
Tenaciousmug Posted May 12, 2011 Author Share Posted May 12, 2011 Nevermind, I used the ereg() instead. (: Works so much better! Got it working. Thanks though! Quote Link to comment https://forums.phpfreaks.com/topic/236271-preg_match-never-working/#findComment-1214751 Share on other sites More sharing options...
fugix Posted May 12, 2011 Share Posted May 12, 2011 The code that requinix posted was for you to use in your preg_match() function instead of what you had. Nevertheless, glad you figured it out Quote Link to comment https://forums.phpfreaks.com/topic/236271-preg_match-never-working/#findComment-1214753 Share on other sites More sharing options...
MadTechie Posted May 12, 2011 Share Posted May 12, 2011 Working until PHP6.. as ereg will be removed! as is "DEPRECATED as of PHP 5.3.0" If you know RegEx your be fine.. but by your questions i assume you don't know it, $depositamt = $_POST['depositamt']; if (!preg_match("^[0-9]+$", $depositamt)) should be $depositamt = $_POST['depositamt']; if (!preg_match('/^[0-9]+$/', $depositamt)) translated into English that says if the following does not match depositamt must have 1 or more number from the start to the end (nothing else) Quote Link to comment https://forums.phpfreaks.com/topic/236271-preg_match-never-working/#findComment-1214756 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.