diff options
author | Andrey Andreev <narf@devilix.net> | 2017-01-06 11:37:30 +0100 |
---|---|---|
committer | Andrey Andreev <narf@devilix.net> | 2017-01-06 11:37:30 +0100 |
commit | bda2efd42e8896c03d6a95591a6d77bcb761ce26 (patch) | |
tree | f8a26b0573e09cfc98a18a54234b210aef151b67 /system/libraries/Form_validation.php | |
parent | ad29ba888068485de20980df240ae786aa53a9ab (diff) |
Add valid_mac() FV rule
Close #3992
Diffstat (limited to 'system/libraries/Form_validation.php')
-rw-r--r-- | system/libraries/Form_validation.php | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index 6f654deb4..11f98f2a9 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -1284,6 +1284,31 @@ class CI_Form_validation { // -------------------------------------------------------------------- /** + * Validate MAC address + * + * @param string $mac + * @return bool + */ + public function valid_mac($mac) + { + if ( ! is_php('5.5')) + { + // Most common format, with either dash or colon delimiters + if (preg_match('#\A[0-9a-f]{2}(?<delimiter>[:-])([0-9a-f]{2}((?P=delimiter)|\z)){5}#i', $mac)) + { + return TRUE; + } + + // The less common format; e.g. 0123.4567.89ab + return (bool) preg_match('#((\A|\.)[0-9a-f]{4}){3}\z#i', $mac); + } + + return (bool) filter_var($mac, FILTER_VALIDATE_MAC); + } + + // -------------------------------------------------------------------- + + /** * Alpha * * @param string |