mais não estou conseguindo informar a ER como eu faço para mostrar somente numeros?
function numeros($n){ if(!ereg('[0-9]',$n)){ echo "errado"; }else{ echo "certo"; } } $num = "22222"; echo numeros($num);
Posted 03/07/2007, 15:57
function numeros($n){ if(!ereg('[0-9]',$n)){ echo "errado"; }else{ echo "certo"; } } $num = "22222"; echo numeros($num);
Posted 03/07/2007, 16:30
^([0-9]+)$
Renan Gonçalves
renan.saddam@gmail.com
(WebSite / Gmail / orkut / Windows Live! Messenger)
"Aquele que se define se limita."
Posted 03/07/2007, 17:56
Nota: preg_match(), você pode também utilizar as expressões regulares compátiveis com perl, uma alternativar veloz a função ereg().
if(!preg_match('/\d/',$n)){ (..)
Posted 03/07/2007, 19:28
<?php $num = "22222"; echo (is_numeric($num)) ? "Certo" : "Errado"; ?>
Posted 06/07/2007, 21:31
boa tarde, eu estou tentando verificar se o valor digitado foi somente numeros [...]
Negativo. De acordo com o manual:Acredito que era mais façil usar a função "is_numeric()" ela é própria para isso ....
Neste caso devemos trabalhar com funções de string mesmo.is_numeric
(PHP 4, PHP 5)
is_numeric — Finds whether a variable is a number or a numeric string
Description
bool is_numeric ( mixed $var )
Finds whether the given variable is numeric. Numeric strings consist of optional sign, any number of digits, optional decimal part and optional exponential part. Thus +0123.45e6 is a valid numeric value. Hexadecimal notation (0xFF) is allowed too but only without sign, decimal and exponential part.
0 membro(s), 1 visitante(s) e 0 membros anônimo(s)