Raised This Month: $32 Target: $400
 8% 

Only Numbers


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Dragos
Senior Member
Join Date: Oct 2018
Location: Romania
Old 02-20-2021 , 15:05   Only Numbers
Reply With Quote #1

Hello,

I'm pretty sure it was a function like this.

So, It check If the entered words contain only numbers, no words

PHP Code:
new szArg[192];
    
read_argsszArgcharsmaxszArg ) );
    
remove_quotesszArg );
    new 
ids str_to_num(szArg)
    
    if(
ids == 0) {
        
culoare(id"!g[!tSYSTEM!g] !tWe Accept Only Numbers")
        return 
PLUGIN_HANDLED;
    } 
If I write like 123456 it block me
But If I type 123456A, it allow him and pass next
__________________
sup

Last edited by Dragos; 02-20-2021 at 15:05.
Dragos is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-20-2021 , 15:33   Re: Only Numbers
Reply With Quote #2

Use is_str_num()
__________________
Bugsy is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 02-20-2021 , 16:29   Re: Only Numbers
Reply With Quote #3

PHP Code:

stock bStringAreNumbers
(const String[])
{
   for(new 
imaxloop strlen(String); maxloopi++)
   {
      if( ! ( 
'0' <= String] <= '9' ) ) return false;
   }
   return 
true;


although listen for what bugsy told you, this example is just for clarification!
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 02-20-2021 at 16:40.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Dragos
Senior Member
Join Date: Oct 2018
Location: Romania
Old 02-20-2021 , 18:21   Re: Only Numbers
Reply With Quote #4

My bad, I wanted to say that If I type 123456 [Need to type regular numbers to pass] it let me go, but If I type 123456A it still pass me <-- [And this is what I want to block] [What I want to block it's that , If I type some numbers and in that numbers contain a words is should return ]
__________________
sup

Last edited by Dragos; 02-20-2021 at 18:39.
Dragos is offline
Dragos
Senior Member
Join Date: Oct 2018
Location: Romania
Old 02-20-2021 , 18:43   Re: Only Numbers
Reply With Quote #5

It lock like doing it negative it solved my problem

PHP Code:
if(!bStringAreNumbers(szArg)) {
        
culoare(id"!g[!tSYSTEM!g] !tWe Accept Only Numbers");
        return 
PLUGIN_HANDLED;
    } 
Ty
__________________
sup

Last edited by Dragos; 02-20-2021 at 18:44.
Dragos is offline
loiraolhosazul
Member
Join Date: May 2020
Old 02-20-2021 , 21:51   Re: Only Numbers
Reply With Quote #6

Or:

PHP Code:
stock bool:xValidNumber(const xStr[])
{
    new const 
xNumbers[][] =
    {
        
"0""1""2""3""4""5""6""7""8""9"
    
}
    
    new 
xLen strlen(xStr)
    new 
iaxValids
    
    
for(0xLeni++)
    {
        for(
0sizeof(xNumbers); a++)
        {
            if(
xStr[i] == xNumbers[a][0])
            {
                
xValids ++
                break
            }
        }
    }
    
    if (
xValids != xLen)
        return 
false
    
    
return true

loiraolhosazul is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-20-2021 , 23:06   Re: Only Numbers
Reply With Quote #7

Beating this one to death guys..I'd just use the native is_str_num() and call it a day. Natsheh's function is better/more efficient than what you posted, loiraolhosazul.
__________________
Bugsy is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 21:59.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode