IsNumeric()

11/01/2011 19:31 .Sags Barney .!#1
Es ist wirklich einfach ,aber vll braucht es jemand.
PHP Code:
BOOL IsNumericCHAR *txt )
{
    
BOOL STATUS    TRUE;
    
unsigned i    NULL;

    while( 
STATUS && strlentxt ) )
    {
        switch( 
txt[i] )
        {
            case 
'0':
            case 
'1':
            case 
'2':
            case 
'3':
            case 
'4':
            case 
'5':
            case 
'6':
            case 
'7':
            case 
'8':
            case 
'9':
            case 
'.'// maybe float?!
                // everything ok
            
break;
            default:
                
// w8, this shit aint numeric
                
STATUS FALSE;
        }
        
i++;
    }

    return 
STATUS;

11/01/2011 20:23 Raz9r#2
Credits: silentchris
100% C&P von WR-Cheats

Proof: [Only registered and activated users can see links. Click Here To Register...]
11/02/2011 20:29 Shadow992#3
Quote:
Originally Posted by __underScore View Post
Credits: silentchris
100% C&P von WR-Cheats

Proof: [Only registered and activated users can see links. Click Here To Register...]
Noch dazu geht es Prozessor schonender und um einiges kürzer:

PHP Code:
BOOL IsNumericCHAR *txt 

    
BOOL STATUS    TRUE
    
unsigned i    NULL

    while( 
STATUS && strlentxt ) ) 
    { 
        if ((
txt[i]<'0' or txt[i]>'9') and txt[i]!='.')
           
STATUS=FALSE;
        
i++; 
    } 

    return 
STATUS

11/06/2011 11:24 Raz9r#4
Quote:
Originally Posted by Shadow992 View Post
Noch dazu geht es Prozessor schonender und um einiges kürzer:

PHP Code:
BOOL IsNumericCHAR *txt 

    
BOOL STATUS    TRUE
    
unsigned i    NULL

    while( 
STATUS && strlentxt ) ) 
    { 
        if ((
txt[i]<'0' or txt[i]>'9') and txt[i]!='.')
           
STATUS=FALSE;
        
i++; 
    } 

    return 
STATUS

Code:
bool IsNumeric(char *szText)
{
for(; *szText != 0; szText++)
if((*szText < '0' || *szText > '9') && *szText != '.')
return false;
return true;
}