<?php
function validarCelular($celular)
{
static $regex;
if ($regex === null) {
//Coloquei em um array para identificar melhor
11, 12, 13, 14, 15, 16, 17, 18, 19,
21, 22, 24, 27, 28,
91, 92, 93, 94, 95,
81, 82, 83, 84, 85, 86, 87,
31, 32, 33, 34, 35, 37, 38,
71, 73, 74, 75, 77, 79,
61, 62, 63, 64, 65, 66, 67, 68, 69,
49, 51, 53, 54, 55
));
//Gera a regex
$regex = '#^(\((' . $ddds . ')\) 9|\((?!' . $ddds . ')\d{2}\) )[6789]\d{3}-\d{4}$#';
}
}
var_dump( validarCelular
('(21) 96000-0000') ); var_dump( validarCelular
('(21) 6000-0000') ); var_dump( validarCelular
('(10) 6000-0000') ); var_dump( validarCelular
('(10) 96000-0000') );
PD9waHAKCmZ1bmN0aW9uIHZhbGlkYXJDZWx1bGFyKCRjZWx1bGFyKQp7CiAgICBzdGF0aWMgJHJlZ2V4OwoKICAgIGlmICgkcmVnZXggPT09IG51bGwpIHsKICAgICAgICAvL0NvbG9xdWVpIGVtIHVtIGFycmF5IHBhcmEgaWRlbnRpZmljYXIgbWVsaG9yCiAgICAgICAgJGRkZHMgPSBpbXBsb2RlKCd8JywgYXJyYXkoCiAgICAgICAgICAgIDExLCAxMiwgMTMsIDE0LCAxNSwgMTYsIDE3LCAxOCwgMTksCiAgICAgICAgICAgIDIxLCAyMiwgMjQsIDI3LCAyOCwKICAgICAgICAgICAgOTEsIDkyLCA5MywgOTQsIDk1LAogICAgICAgICAgICA4MSwgODIsIDgzLCA4NCwgODUsIDg2LCA4NywKICAgICAgICAgICAgMzEsIDMyLCAzMywgMzQsIDM1LCAzNywgMzgsCiAgICAgICAgICAgIDcxLCA3MywgNzQsIDc1LCA3NywgNzksCiAgICAgICAgICAgIDYxLCA2MiwgNjMsIDY0LCA2NSwgNjYsIDY3LCA2OCwgNjksCiAgICAgICAgICAgIDQ5LCA1MSwgNTMsIDU0LCA1NQogICAgICAgICkpOwoKICAgICAgICAvL0dlcmEgYSByZWdleAogICAgIC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