Initial Commit
This commit is contained in:
52
inc/helpers/validation-rules/class-domain.php
Normal file
52
inc/helpers/validation-rules/class-domain.php
Normal file
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
/**
|
||||
* Adds a validation rules that allows us to check if a given parameter exists.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage Helpers/Validation_Rules
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Helpers\Validation_Rules;
|
||||
|
||||
use WP_Ultimo\Dependencies\Rakit\Validation\Rule;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Adds a validation rules that allows us to check if a given parameter exists.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class Domain extends Rule {
|
||||
|
||||
/**
|
||||
* Error message to be returned when this value has been used.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string
|
||||
*/
|
||||
protected $message = ':attribute :value is not valid';
|
||||
|
||||
/**
|
||||
* Parameters that this rule accepts.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var array
|
||||
*/
|
||||
protected $fillableParams = array(); // phpcs:ignore
|
||||
/**
|
||||
* Performs the actual check.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param mixed $value Value being checked.
|
||||
*/
|
||||
public function check($value) : bool { // phpcs:ignore
|
||||
|
||||
return (bool) preg_match('/^(?!\-)(?:(?:[a-zA-Z\d][a-zA-Z\d\-]{0,61})?[a-zA-Z\d]\.){1,126}(?!\d+)[a-zA-Z\d]{1,63}$/', (string) $value);
|
||||
|
||||
} // end check;
|
||||
|
||||
} // end class Domain;
|
Reference in New Issue
Block a user