User not logged in - login - register
Home Calendar Books School Tool Photo Gallery Message Boards Users Statistics Advertise Site Info
go to bottom | |
 Message Boards » » form validation - regular expression function Page [1]  
Novicane
All American
15413 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

Novicane
All American
15413 Posts
user info
edit post

the client side will not pop up with the error. Will try yours monday and see how it goes.

Server side php works good.

[Edited on October 24, 2010 at 11:02 AM. Reason : ss]

10/24/2010 11:01:17 AM

 Message Boards » Tech Talk » form validation - regular expression function Page [1]  
go to top | |
Admin Options : move topic | lock topic

© 2024 by The Wolf Web - All Rights Reserved.
The material located at this site is not endorsed, sponsored or provided by or on behalf of North Carolina State University.
Powered by CrazyWeb v2.38 - our disclaimer.