Welcome Guest, Not a member yet? Register   Sign In
Custom Form Validation Rules list -- Please contribute!
#1

[eluser]CroNiX[/eluser]
I thought it would be nice if people had a single thread that contained custom validation rules that they use in order to help others. Please provide a detailed explanation of your rule(s). PLEASE use CODE TAGS.
Edit: This probably should have been posted in Ignited Code, please feel free to move it.
Ill Start:

Code:
<?php
// Allows alphanumeric (case insensitive), dashes, underscores, perids and spaces.  Useful for addresses.
function is_address($str)
{
    $this->set_message('is_address', 'The %s field may only contain alpha-numeric characters, spaces, underscores, periods and dashes.');
    return ( ! preg_match("/^([-a-z0-9_. -])+$/i", $str)) ? FALSE : TRUE;
}
#2

[eluser]jedd[/eluser]
[quote author="CroNiX" date="1255484468"]
Edit: This probably should have been posted in Ignited Code, please feel free to move it.
[/quote]

In fact it's the kind of thing that cries out to be banged into the wiki, don't you think?

Unless you reckon that in six months from now it be easier for some random wanderer to find this thread on page 153 of the forum index, rather than the validation rules - user contributions page in the wiki? There's already a bunch of vaguely appropriate pages in there - perhaps you could sort through them, consolidate them where appropriate?
#3

[eluser]Colin Williams[/eluser]
You know you can just return the function call.

Code:
return preg_match("/^([-a-z0-9_. -])+$/i", $str);

What you are essentially doing with your check is

Code:
return ! TRUE ? FALSE : TRUE;
#4

[eluser]CroNiX[/eluser]
@Colin-Yes, I was just keeping the same format that they use internally in the validation class.




Theme © iAndrew 2016 - Forum software by © MyBB