Pregunta

Soy más nuevo relacionado con Regexp en PHP...

Necesito crear un expresión regular para filtrar teléfonos móviles portugueses, ¿alguien puede ayudarme y explicarme cómo lo hago?(Para que lo entienda)

Normas:

The integer/string must have 9chars;
The first char must be a '9';
The second one can be '1,2,3,6' (Chars are separeted by commas);
The other chars must be in range of '0-9';
¿Fue útil?

Solución

#9[1236][0-9]{7}#

Deberias hacer eso ;)

Explicación:

# <-- delimiter
    9 <-- 9
    [1236] <-- either of the chars in the brackets
    [0-9]{7} <-- 0-9  7 times
# <-- delimiter

Usar:Si desea comprobar si algo es un número de teléfono válido, utilice:

$isValid = preg_match('#^9[1236][0-9]{7}$#', $phoneNumber);

Observe la ^ y $.Estos aseguran que solo esté el número de teléfono y nada más.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top