Yii2 Network Addresses Validators
Yii2 Extension that provide validators and features for validate network addresses, (*1)
- IPv4Validator: Validate IPv4 address or IPv4 netmask
- IPv6Validator: Validate IPv6 address
- MACValidator: Validate MAC address
- NetAddressValidator: Validate IPv4 address or IPv4 netmask or IPv6 address or MAC address
, (*2)
Installation
The preferred way to install this extension is through composer., (*3)
Either run, (*4)
php composer.phar require --prefer-dist onixsib/yii2-net-address-validators "*"
or add, (*5)
"onixsib/yii2-net-address-validators": "*"
to the require section of your composer.json
file., (*6)
Usage
Add the rules as the following example, (*7)
use Yii;
use yii\base\Model;
use onixsib\validators\IPv4Validator;
use onixsib\validators\IPv6Validator;
use onixsib\validators\MACValidator;
use onixsib\validators\NetAddressValidator;
class NetworkInterface extends Model
{
public $name;
public $IPv4;
public $IPv4Netmask;
public $IPv6;
public $MAC;
/**
* @return array the validation rules.
*/
public function rules()
{
return [
// name is required
['name', 'required'],
// IPv4 validator
['IPv4', IPv4Validator::className()],
// IPv6 validator
['IPv6', IPv6Validator::className()],
// MAC validator
['MAC', MACValidator::className()]
];
}
}