Check if hex code is valid - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Check if hex code is valid (
/showthread.php?tid=458310)
Check if hex code is valid -
IgrexolonO - 15.08.2013
Hello. I'm looking for a funtion, that will check if hex code is valid 'color code'.
For example: FF0097 is valid color code.
GGGGGG isn't valid code.
Regards.
Re: Check if hex code is valid -
Lyksus - 16.08.2013
why do you need that
Re: Check if hex code is valid -
Pottus - 16.08.2013
I take it you have a string input ?
Re: Check if hex code is valid -
[KHK]Khalid - 16.08.2013
Have you tried the
x or
h parameter in sscanf?
Re: Check if hex code is valid -
Ballu Miaa - 16.08.2013
Quote:
Originally Posted by ******
If it isn't valid, it won't compile.
|
This!
Or It will crash the server on runtime if an invalid hex code is used.
Re: Check if hex code is valid -
IgrexolonO - 16.08.2013
Yh. In fact I was rewriting MTA's color chat. And I already wrote my own function, so if anybody need it, here it goes:
Код:
stock isValidHexCode(code[])
{
new checked;
for(new i;i<6;i++)
{
if(IsNumeric(code[i])) checked+=1;
else if((code[i] == 'A' || code[i] == 'a') || (code[i] == 'B' || code[i] == 'b') || (code[i] == 'C' || code[i] == 'c') || (code[i] == 'D' || code[i] == 'd') || (code[i] == 'E' || code[i] == 'e') || (code[i] == 'F' || code[i] == 'f')) checked+=1;
}
if(checked == 6) return true;
return false;
}
It works for 6 letters in hex code, so you have to input 6 letters string into function for check.