ereg() doesen't handle num/char mix....


#1

hi there, i’m trying to validate just numbers in a given variable, here`s da code;

$aka=00; if (ereg('[0-9]',$aka)) { echo ("no letters"); }else{ echo("str contain letters"); }

well, this works fine for $aka=1234 or $aka=asd, but it doesen’t handle the num/char mix, by example if var $aka = 0a2, i get a blank page w/nothing displayed, and if i put this $aka = k9 it evaluates to true ( “no leters” ?) but $aka = 9k displays nothing.

can some one helpme?

thanx in advance & an apologuise 4 the really bad english… :D


#2

How about:

[php]

if (ereg(’^[[:digit:]]+$’, $aka))
{
echo (“no letters”);
}else{
echo(“str contains letters”);
}
[/php]


#3

thanx for the promptly reply carella,

but still have the same problem, even as i copy/paste the code u wrote, just dont work.

let’s take for example;

$aka=9800gui the result is a blank page
$aka=123 result= no letters
$aka=asd result= no letters
$aka=asd00 result= no letters
$aka=00asd result= blank page
$aka=0a8sd7 result= blank page
$aka=ASD result=no letters

as i’m trying this there’s no othercode besides an extra echo at the EOF,

what i’m doing wrong?

thanx again 4 ur kindness


#4

ok i see u edit your post, thanx,

but i’m very sorry about this, 'cause i’m an a$$hole, problem was in $aka=123s3d wich should had been; $aka=“123s3d”, i’m very sorry about this “brute” error.

thanx greatly for your kindness…


#5

Sorry about the edit, I meant to repost, but ended up editing instead.

So is everything working ok now?


#6

yeah, thanx alot 4 ur time and advise carella…


#7

FYI - have you looked here - http://www.php.net/manual/en/ref.var.php ?
There are a lot of functions to check a variables type with out going through the regex :). So why work so hard?


#8

WOOOOOOOOOWWWW!!!

no i haven’t, as a matter of fact i even know their existence, thanx a lot lig, carella, ur advise was, is and would be greatly aprecciated.

cya