Created
December 12, 2018 17:38
-
-
Save thewasta/4661208b0c60d49940aaacc2dbb78231 to your computer and use it in GitHub Desktop.
This Preg_Match is for use number,lowercase,capital letters,graphic accent and
add the min and max character. Also you can add global, multi line, insensitive.
You have to write a associative array for example:
['NUMBERS'=>'0-9','SIZECHARS'=>'6,12']
output:'/[0-9]{6,8}+$/'.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Created by Schenier Aldair Lopez | |
* Date: 12/12/18 | |
* Time: 18:30 | |
* | |
*/ | |
function pregMatch(array $diccionario,$variable){ | |
if (empty($diccionario['SPACE'])){ | |
$diccionario['SPACE'] = ' '; | |
} | |
if (empty($diccionario['SIZECHARS'])){ | |
$diccionario['SIZECHARS'] = '6,20'; | |
} | |
if (empty($diccionario['abc'])){ | |
$diccionario['abc']='a-z'; | |
} | |
if (empty($diccionario['ABC'])){ | |
$diccionario['ABC']='A-Z'; | |
} | |
$preg = '/['.'{NUMBERS}'.''.'{abc}'.''.'{ABC}'.''.'{TILDES}'.''.'{SPACE}'.']'.'{{SIZECHARS}}'.'+$/'.'{MORE}'.''; | |
if (!array_key_exists('NUMBERS',$diccionario)){ | |
$preg = str_replace('{NUMBERS}','',$preg); | |
} | |
if (!array_key_exists('abc',$diccionario)){ | |
$preg = str_replace('{abc}','',$preg); | |
} | |
if (!array_key_exists('ABC',$diccionario)){ | |
$preg = str_replace('{ABC}','',$preg); | |
} | |
if (!array_key_exists('TILDES',$diccionario)){ | |
$preg = str_replace('{TILDES}','',$preg); | |
} | |
if (!array_key_exists('SPACE',$diccionario)){ | |
$preg = str_replace('{SPACE}','',$preg); | |
} | |
if (!array_key_exists('SIZECHARS',$diccionario)){ | |
$preg = str_replace('{SIZECHARS}','',$preg); | |
}if (!array_key_exists('MORE',$diccionario)){ | |
$preg = str_replace('{MORE}','',$preg); | |
} | |
foreach ($diccionario as $key => $value){ | |
$preg = str_replace('{'.$key.'}',$value,$preg); | |
} | |
if (preg_match($preg,$variable)){ | |
return true; | |
}else{ | |
return false; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment