- Class verify{
- /**
- * Verify user name
- * @param string $value
- * @param int $length
- * @return Boolean
- */
- public static function Isnames ($value, $minLen =2, $maxLen =20, $charset = ' all ') {
- if (empty ($value))
- return false;
- Switch ($charset) {
- Case ' EN ': $match = '/^[_\w\d]{'. $minLen. ', '. $maxLen. '} $/iu ';
- Break
- Case ' CN ': $match = '/^[_\x{4e00}-\x{9fa5}\d]{'. $minLen. ', '. $maxLen. '} $/iu ';
- Break
- Default: $match = '/^[_\w\d\x{4e00}-\x{9fa5}]{'. $minLen. ', '. $maxLen. '} $/iu ';
- }
- Return Preg_match ($match, $value);
- }
- /**
- * Verify Password
- * @param string $value
- * @param int $length
- * @return Boolean
- */
- public static function Ispwd ($value, $minLen =5, $maxLen =16) {
- $match = '/^[\\~!@#$%^&* ()-_=+|{} \[\],.? \/:;\ ' \d\w]{'. $minLen. ', '. $maxLen. '} $/';
- $v = Trim ($value);
- if (empty ($v))
- return false;
- Return Preg_match ($match, $v);
- }
- /**
- * Verify Eamil
- * @param string $value
- * @param int $length
- * @return Boolean
- */
- public static function Isemail ($value, $match = '/^[\w\d]+[\w\d-.] *@[\w\d-.] +\. [\w\d] {2,10}$/i ') {
- $v = Trim ($value);
- if (empty ($v))
- return false;
- Return Preg_match ($match, $v);
- }
- /**
- * Verify phone number
- * @param string $value
- * @return Boolean
- */
- public static function Istelephone ($value, $match = '/^0[0-9]{2,3}[-]?\d{7,8}$/') {
- $v = Trim ($value);
- if (empty ($v))
- return false;
- Return Preg_match ($match, $v);
- }
- /**
- * Verify your phone
- * @param string $value
- * @param string $match
- * @return Boolean
- */
- public static function IsMobile ($value, $match = '/^[(86) | 13\D{9}) | (15\d{9}) | (18\d{9}) $/') {
- $v = Trim ($value);
- if (empty ($v))
- return false;
- Return Preg_match ($match, $v);
- }
- /**
- * Verify ZIP Code
- * @param string $value
- * @param string $match
- * @return Boolean
- */
- public static function Ispostcode ($value, $match = '/\d{6}/') {
- $v = Trim ($value);
- if (empty ($v))
- return false;
- Return Preg_match ($match, $v);
- }
- /**
- * Verify IP
- * @param string $value
- * @param string $match
- * @return Boolean
- */
- public static function IsIP ($value, $match = '/^ (25[0-5]|2[0-4][0-9]|[ 0-1] Little Shellfish [0-9]{2}| [1-9] Beckham [0-9] Little Shellfish | [1-9]) \. (25[0-5]|2[0-4][0-9]| [0-1] Little Shellfish [0-9]{2}| [1-9] Beckham [0-9] Little Shellfish | [1-9]|0] \. (25[0-5]|2[0-4][0-9]| [0-1] Little Shellfish [0-9]{2}| [1-9] Beckham [0-9] Little Shellfish | [1-9]|0] \. (25[0-5]|2[0-4][0-9]| [0-1] Little Shellfish [0-9]{2}| [1-9] Beckham [0-9] Little Shellfish | [0-9]) $/'){
- $v = Trim ($value);
- if (empty ($v))
- return false;
- Return Preg_match ($match, $v);
- }
- /**
- * Verify ID Number
- * @param string $value
- * @param string $match
- * @return Boolean
- */
- public static function Isidcard ($value, $match = '/^\d{6} ((1[89)) | ( 2\d)) \d{2} ((0\d) | ( 1[0-2]) ((3[01)) | ( [0-2]\d)] \d{3} (\d| X) {$/i ') {
- $v = Trim ($value);
- if (empty ($v))
- return false;
- else if (strlen ($v) >18)
- return false;
- Return Preg_match ($match, $v);
- }
- /**
- * *
- * Verify URL
- * @param string $value
- * @param string $match
- * @return Boolean
- */
- public static function Isurl ($value, $match = '/^ (http:\/\/)? ( https:\/\/)? ([\w\d-]+\.) +[\w-]+ (\/[\d\w-.\/?%&=]*) $/') {
- $v = Strtolower (Trim ($value));
- if (empty ($v))
- return false;
- Return Preg_match ($match, $v);
- }
- }
- ?>
Copy Code
|
Regular expressions, PHP, URLs