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

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

How about:


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

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

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…

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

So is everything working ok now?

yeah, thanx alot 4 ur time and advise carella…

FYI - have you looked here - ?
There are a lot of functions to check a variables type with out going through the regex :). So why work so hard?


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.


Sponsor our Newsletter | Privacy Policy | Terms of Service