Raised This Month: $51 Target: $400
 12% 

Alphanumeric check


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Nano2e
SourceMod Donor
Join Date: Apr 2012
Location: Australia
Old 10-20-2012 , 23:14   Alphanumeric check
Reply With Quote #1

is there a method for checking if a string is only Alphanumeric?
Nano2e is offline
Predailien12
Senior Member
Join Date: Feb 2010
Location: Your as* hol*
Old 10-20-2012 , 23:24   Re: Alphanumeric check
Reply With Quote #2

Quote:
Originally Posted by Nano2e View Post
is there a method for checking if a string is only Alphanumeric?
Well you should research what the string codes are.

here is the argorithm.

1. Get the Size of String ( using sizeof() )

2. check the letters whether they contain forbidden ones.

3. if they do, return;

4. if not, do what you want

PHP Code:

for(new 0sizeof(String); i++)
{
      if(
String[i] <= ? || String[i] >= ?) return;//Every Char has its own numbered label that indicate the Char
                                                            // For Example, In unicode a has 97 label in Dec. So you can restrict the lable

      
do what you want


Last edited by Predailien12; 10-20-2012 at 23:25.
Predailien12 is offline
11530
Veteran Member
Join Date: Sep 2011
Location: Underworld
Old 10-20-2012 , 23:28   Re: Alphanumeric check
Reply With Quote #3

Code:
stock bool:IsAlphaNumeric(const String:str[])
{
	for (new i = 0; i < sizeof(str); i++)
	{
		if (!IsCharAlpha(str[i]) && !IsCharNumeric(str[i]))
		{
			return false;
		}
	}
	return true;
}
Edit: Use strlen(str) instead of sizeof(str)
__________________

Last edited by 11530; 10-22-2012 at 09:34.
11530 is offline
Nano2e
SourceMod Donor
Join Date: Apr 2012
Location: Australia
Old 10-20-2012 , 23:29   Re: Alphanumeric check
Reply With Quote #4

iv been working on a bool thing to check just struggling atm, why im asking if something already exists but ty for you input!
Nano2e is offline
Nano2e
SourceMod Donor
Join Date: Apr 2012
Location: Australia
Old 10-20-2012 , 23:31   Re: Alphanumeric check
Reply With Quote #5

Quote:
Originally Posted by 11530 View Post
Code:
stock bool:IsAlphaNumeric(const String:str[])
{
	for (new i = 0; i < sizeof(str); i++)
	{
		if (!IsCharAlpha(str[i]) && !IsCharNumeric(str[i]))
		{
			return false;
		}
	}
	return true;
}
looks pretty similar to what iv been working to get haha ^^ but ty for this ill give it a whiz
Nano2e is offline
Nano2e
SourceMod Donor
Join Date: Apr 2012
Location: Australia
Old 10-20-2012 , 23:41   Re: Alphanumeric check
Reply With Quote #6

okay got it working, ty allot fellas
Nano2e is offline
Predailien12
Senior Member
Join Date: Feb 2010
Location: Your as* hol*
Old 10-20-2012 , 23:42   Re: Alphanumeric check
Reply With Quote #7

Quote:
Originally Posted by 11530 View Post
Code:
stock bool:IsAlphaNumeric(const String:str[])
{
	for (new i = 0; i < sizeof(str); i++)
	{
		if (!IsCharAlpha(str[i]) && !IsCharNumeric(str[i]))
		{
			return false;
		}
	}
	return true;
}
Oops I didn't know that functions.

TY for teaching me that ones
Predailien12 is offline
FaTony
Veteran Member
Join Date: Aug 2008
Old 10-20-2012 , 23:42   Re: Alphanumeric check
Reply With Quote #8

This is UTF-8 unsafe. You should never access individual bytes of string if you want to support code points outside of ASCII range. Unfortunately, there is no easy way to access code points either.

I've made a proposal about better strings in the donor forum but so far it didn't gain much support.
__________________

Last edited by FaTony; 10-20-2012 at 23:54.
FaTony is offline
BAILOPAN
Join Date: Jan 2004
Old 10-21-2012 , 00:55   Re: Alphanumeric check
Reply With Quote #9

This function is UTF-8 safe, because out-of-range bytes will fail the character class tests.
__________________
egg

Last edited by BAILOPAN; 10-21-2012 at 01:04.
BAILOPAN is offline
Predailien12
Senior Member
Join Date: Feb 2010
Location: Your as* hol*
Old 10-21-2012 , 01:10   Re: Alphanumeric check
Reply With Quote #10

Quote:
Originally Posted by BAILOPAN View Post
This function is UTF-8 safe, because out-of-range bytes will fail the character class tests.
Hey. I have some question.

I want to make some extension to make 64-bit integer or something.

could you please, inform me where to learn the basic..?
Predailien12 is offline
Reply



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 06:25.


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