SA-MP Forums Archive
hex code color - 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: hex code color (/showthread.php?tid=662589)



hex code color - Cezar98 - 06.01.2019

How can i check for invalid hex code color in a dialog with ShowPlayerDialog if player insert an invalid hex code color in a dialog to get a message like this ''invalid hex color'' but how to check for this ?


Re: hex code color - GRiMMREAPER - 06.01.2019

Quote:
Originally Posted by Y_Less
View Post
sscanf x will fail on them.

Or if you want to scan a whole string you could use a very complex regex:

\{[^}]*[^a-fA-F0-9}].*?\}|\{[a-fA-F0-9]{0,5}\}|\{[a-fA-F0-9]{7,}\}|^[^{]*\}|\{[^}]*$

Which will check for any {} with a non-hex character between them, or 0-5 hex characters, or 7+ hex characters, or an unopened brace, or an unclosed brace.
Wouldn't this suffice?

Code:
/^#[0-9A-F]{6}$/i



Re: hex code color - Cezar98 - 06.01.2019

Quote:
Originally Posted by Y_Less
View Post
No.

a) That's not the correct syntax for colour codes.

b) They want to find invalid ones, not valid ones.

c) You forgot lower-case letters.
Explain me how can i use this

\{[^}]*[^a-fA-F0-9}].*?\}|\{[a-fA-F0-9]{0,5}\}|\{[a-fA-F0-9]{7,}\}|^[^{]*\}|\{[^}]*$