Skip to content

Network Rules

Network validation rules check IP addresses, email addresses, URLs, and phone numbers.

RuleParametersExampleError Message
ip$v->rule('ip', 'field'){field} must be a valid IP address
ipv4$v->rule('ipv4', 'field'){field} must be a valid IPv4 address
ipv6$v->rule('ipv6', 'field'){field} must be a valid IPv6 address
email$v->rule('email', 'field'){field} is not a valid email address
emailDNS$v->rule('emailDNS', 'field'){field} must be a valid email address with an active DNS record
url$v->rule('url', 'field'){field} is not a valid URL
urlActive$v->rule('urlActive', 'field'){field} must be an active URL
urlStrict$v->rule('urlStrict', 'field'){field} is not a valid public URL
phonecountry?$v->rule('phone', 'field', 'US'){field} is not a valid phone number

Note: Parameters marked with ? are optional.

Email security: RFC 5321 compliant, max length validation, XSS/injection prevention.

URL protocols: http://, https://, ftp:// only.

urlStrict extras: Requires dot in domain, catches typos (ww. vs www.), rejects numeric TLDs.

DNS lookups: emailDNS and urlActive add latency - use basic rules for high-traffic forms.

Without country: validates 7-15 digits. With country: country-specific format.

Supported countries: US, CA, UK/GB, AU, IN, DE, FR, IT, ES, BR, MX

Accepted formats: +1-555-123-4567, 5551234567, (555) 123-4567


Valicomb supports two syntax styles: rule-based (map rules to fields) and field-based (map fields to rules).

use Frostybee\Valicomb\Validator;
$v = new Validator($data);
$v->rules([
'ip' => [
['client_ip'],
['proxy_ip']
],
'ipv4' => [
['server_ip']
],
'ipv6' => [
['ipv6_address']
],
'email' => [
['user_email'],
['billing_email']
],
'emailDNS' => [
['primary_email']
],
'url' => [
['website'],
['blog_url']
],
'urlActive' => [
['callback_url']
],
'urlStrict' => [
['public_website']
],
'phone' => [
['mobile_phone'],
['office_phone', 'US']
]
]);
$v->validate();
use Frostybee\Valicomb\Validator;
$v = new Validator($data);
$v->mapManyFieldsToRules([
'email' => ['required', 'email'],
'backup_email' => ['optional', 'emailDNS'],
'website' => ['optional', 'urlStrict'],
'api_callback' => ['required', 'urlActive'],
'phone' => ['required', ['phone', 'US']],
'fax' => ['optional', 'phone'],
'server_ip' => ['required', 'ipv4'],
'client_ip' => ['optional', 'ip']
]);
$v->validate();