Welcome Guest, Not a member yet? Register   Sign In
custom validation rules for field
#1

[eluser]pallavi312[/eluser]
hi,

how to set custom validation rules to field while doing form validation?
eg. for last name it shouldn't start & end with special character ?
how can this be implemented?
Please reply earlier.....
#2

[eluser]verynewtothis[/eluser]
write regex in the callback functions. From your last post regarding the phone number validation, I think you already have an idea of callback functions so this should not be problem for you.
#3

[eluser]pallavi312[/eluser]
hello,
i don't have problem in implememnting callback function. but i want to pass some additional parametes to function . as i read that callback function get value of post value of field name & field name(like firstname), but if i want to pass one more parameters like array how can this be achived?

or i have also have custom function for checking special characters for field . but problem is how to pass third parameters to callback function?
any idea or other solutions would be appreciable....
#4

[eluser]verynewtothis[/eluser]
may be you could define an instance variable of type array and set it up before calling your validation.. the variable will be available to you every where in your class.

like this: (pseudo code)
Code:
class MyClass {
private $myArray;

__construct() {
    $myArray = array();
}
function yourFunction()
{
   $this->myArray = array('a' = 1, b='2');
   //setup validation and callbacks
}
function _callbackfunction(){
   //The array will be available here for your use.
     var_dump($this->myArray)
}
}

Remember that this is just a psudo code...




Theme © iAndrew 2016 - Forum software by © MyBB