Skip to content

Commit

Permalink
update some format
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Apr 26, 2020
1 parent 9ac09cd commit faf3eed
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
6 changes: 3 additions & 3 deletions src/Valid.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use function is_numeric;

/**
* Class Valid - Simple Data Validator
* Class Valid - Simple Data Validator TODO
*
* @package Inhere\Validate
*/
Expand Down Expand Up @@ -42,9 +42,9 @@ public function getData(): array
return self::$data;
}

/**********************************************************************************************
/*************************************************************************
* =========== validate data field value and return
*********************************************************************************************/
*************************************************************************/

/**
* @param string $field
Expand Down
37 changes: 24 additions & 13 deletions src/Validators.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ class Validators
{
use NameAliasTrait;

public const REGEX_DATE = '/^([\d]{4})-((?:0?[\d])|(?:1[0-2]))-((?:0?[\d])|(?:[1-2][\d])|(?:3[01]))( [\d]{2}:[\d]{2}:[\d]{2})?$/';

public const REGEX_DATE_FMT = '/^([\d]{4})-((0?[\d])|(1[0-2]))-((0?[\d])|([1-2][\d])|(3[01]))( [\d]{2}:[\d]{2}:[\d]{2})?$/';

public const REGEX_ABS_URL = '/^(https?:)?\/\/[$~:;#,%&_=\(\)\[\]\.\? \+\-@\/a-zA-Z0-9]+$/';

/**
* @var array
*/
Expand Down Expand Up @@ -1290,33 +1296,33 @@ public static function afterOrEqualDate($val, $afterDate): bool
/**
* Check for date format
*
* @param string $date Date to validate
* @param string|mixed $date Date to validate
*
* @return bool Validity is ok or not
*/
public static function isDateFormat($date): bool
{
return (bool)preg_match(
'/^([\d]{4})-((0?[\d])|(1[0-2]))-((0?[\d])|([1-2][\d])|(3[01]))( [\d]{2}:[\d]{2}:[\d]{2})?$/',
$date
);
if (!$date || !is_string($date)) {
return false;
}

return 1 === preg_match(self::REGEX_DATE_FMT, $date);
}

/**
* Check for date validity
*
* @param string $date Date to validate
* @param string|mixed $date Date to validate
*
* @return bool Validity is ok or not
*/
public static function isDate($date): bool
{
if (!preg_match(
'/^([\d]{4})-((?:0?[\d])|(?:1[0-2]))-((?:0?[\d])|(?:[1-2][\d])|(?:3[01]))( [\d]{2}:[\d]{2}:[\d]{2})?$/',
$date,
$matches
)
) {
if (!$date || !is_string($date)) {
return false;
}

if (!preg_match(self::REGEX_DATE, $date, $matches)) {
return false;
}

Expand Down Expand Up @@ -1392,6 +1398,11 @@ public static function isFloat($float): bool
return (string)((float)$float) === (string)$float;
}

/**
* @param float|mixed $float
*
* @return bool
*/
public static function isUnsignedFloat($float): bool
{
if (!is_scalar($float)) {
Expand Down Expand Up @@ -1486,7 +1497,7 @@ public static function absoluteUrl($url): bool
return false;
}

return 1 === preg_match('/^(https?:)?\/\/[$~:;#,%&_=\(\)\[\]\.\? \+\-@\/a-zA-Z0-9]+$/', $url);
return 1 === preg_match(self::REGEX_ABS_URL, $url);
}

/**
Expand Down

0 comments on commit faf3eed

Please sign in to comment.