IP Mask validator February 12, 2006
Posted by rossoft in CakePHP.trackback
Added to my validator vendor package more validators (IpValidator and NetmaskValidator)
Example of usage (read the phpdoc info on the source files for full doc):
$validate=array(
'ip'=>array(
array(VALID_NOT_EMPTY,'Not blank'),
array(VALID_IP,'Not valid ip',array(true,'network','mask'))),
'network'=>array(
array(VALID_NOT_EMPTY,'Not blank'),
array(VALID_IP,'Not valid ip network')),
'network_mask'=>array(
array(VALID_NOT_EMPTY,'Not blank'),
array(VALID_NETMASK,'Not valid network mask',array(false))));
This will validate:
- The network_mask field is a valid mask. It can’t be in the short format because the param is false. If the param is true, then the mask could be in the short format.
- The network field is a valid ip (it’s in the form xxx.xxx.xxx.xxx)
- The ip field is a valid ip AND is a ip within the range of the network indicated in the field ‘network’ with the mask indicated in the field ‘mask’. If the first param is false, then the 2nd and 3rd parameter are the values directly, nor fields that holds these values.
Comments»
No comments yet — be the first.