Novicane All American 15416 Posts user info edit post |
I've got a premade Regular expression function that seems to not be picking up the reg expression correctly. The previous programmer couldn't get it working and neither could I.
function RegExp($name, $re, $error) { // Client $this->AddJS(" re = $re; if(!re.test(form.$name.value)) { alert('$error'); form.$name.focus(); return false; }
"); // Server if(preg_match($re, $_REQUEST["$name"]) == 0) { $this->errors[] = $error; return false; } else { return true; } }
any ideas?
I pass to the function via php
RegExp('VISIT','/([0-9]{2})\/([0-9]{2})\/([0-9]{4})/', 'Please, enter correct requested ship date.');
note: there are other functions like require, email validate that all work.
[Edited on October 22, 2010 at 4:16 PM. Reason : s]10/22/2010 4:15:30 PM |
EuroTitToss All American 4790 Posts user info edit post |
Quote : | "Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems." |
Which part isn't working. When boiled down to this, it seems to work just fine:
function RegExp($testValue, $re) { if(preg_match($re, $testValue) == 0) { return 'fail'; } else { return 'pass'; } } echo '---'.RegExp('10/23/2010','/([0-9]{2})\/([0-9]{2})\/([0-9]{4})/').'<br>'; echo '---'.RegExp('10/230/2012','/([0-9]{2})\/([0-9]{2})\/([0-9]{4})/').'<br>';
[Edited on October 23, 2010 at 8:00 AM. Reason : code]10/23/2010 7:48:39 AM |