Welcome Guest, Not a member yet? Register   Sign In
Form Validation and Regexp
#1

[eluser]Unknown[/eluser]
Hello I need to set_rules in Form Validation to regexp pattern from database:

I used callback function but it doesn't working.

How can I use it? I found it in form_validation:
Code:
/**
     * Performs a Regular Expression match test.
     *
     * @access    public
     * @param    string
     * @param    regex
     * @return    bool
     */
    function regex_match($str, $regex)
    {
        if ( ! preg_match($regex, $str))
        {
            return FALSE;
        }

        return  TRUE;
    }

But I don't know how to use it.
#2

[eluser]Unknown[/eluser]
You can use it the same way you would use any other validation rule.

Code:
$this->form_validation->set_rules('field name', 'human name', 'regex_match[expression]');

Replace 'expression' with the regular expression from your database.

http://ellislab.com/codeigniter/user-gui...ationrules

However, if your regular expression contains square brackets then you need to use a callback.

There is some more info in this thread: http://ellislab.com/forums/viewthread/185601/

I am not sure why this validation function isn't documented in the user guide. Can anyone provide any insight?
#3

[eluser]toopay[/eluser]
[quote author="ReptileReX" date="1311706107"]How can I use it? ...
But I don't know how to use it.[/quote]

[quote author="birderic" date="1311714118"]I am not sure why this validation function isn't documented in the user guide. Can anyone provide any insight?[/quote]

Mocking the original userguide...

Rule : regex_match
Parameter : YES
Description : Returns FALSE if the form element is not match with regular expression pattern.
Example : regex_match[/^SELECT ([^)]+) FROM ([^)]+)$/i]

(Above example will examinate, if valid SELECT statement present.)

What wrong with you guys? Code is as is. You see above function is just a shorthand to perform regular expression, and you can use it just the way you use preg_match().




Theme © iAndrew 2016 - Forum software by © MyBB