Ninjakreborn Posted January 22, 2007 Share Posted January 22, 2007 I am trying to test for00-00which is numbernumberdashnumbernumberjust like that, it will also always be liek that.I am not having much lukc with the expression, so far I have[00]-[00] THat was my first attempt, then I noticed it failed. so I tried[0-9]-[0-9] That didn't work either.So I modified it like this^[0-9]-[0-9]$ That didn't seem to work, any advice?I want to just make a regular expression $reg = "pattern here"then if (pregmatch($reg, $variable);However I can't get it to work, are any of these even close? Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted January 22, 2007 Author Share Posted January 22, 2007 ([0-9]{2})-([0-9]{2}) How is this, it seems to work, could there be problems with it later on? Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted January 22, 2007 Author Share Posted January 22, 2007 [code]$reg = "([0-9]{2})-([0-9]{2})";if (!preg_match($reg, $_POST['pastyears'])) { echo "Past Years Formatted Incorrectly, must be 00-00 format.<br />"; $temp = "yes";}[/code]That returns something like[quote]Warning: preg_match() [function.preg-match]: Unknown modifier '\' in page(path to file)[/quote]Does anyone see what I might be doing wrong? It worked when I ran that through a tester. Quote Link to comment Share on other sites More sharing options...
obsidian Posted January 22, 2007 Share Posted January 22, 2007 That seems to be the proper regex, however, you don't need to match the digits unless you're referencing them as part of the match elsewhere:[code]<?phppreg_match('|^[0-9]{2}-[0-9]{2}$|', $num);?>[/code] Quote Link to comment Share on other sites More sharing options...
effigy Posted January 22, 2007 Share Posted January 22, 2007 You can reduce[tt] [0-9]{2} [/tt]to[tt] \d{2}[/tt]. The use of[tt] $ [/tt]is good, but subtly wrong in this case (which I'm often just as guilty of). Use[tt] \z [/tt]instead, because[tt] $ [/tt][i]can[/i], but not necessarily, match before a new line. 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.