code help (calling Perrin or crow)

Post Reply
perrinoia
Site Admin
Posts: 3732
Joined: Sun Jul 01, 2012 7:18 pm

Re: code help (calling Perrin or crow)

Post by perrinoia »

Code: Select all

// returns true if this contains only characters found in that. -perrinoia
function String::onlyContains(%this, %that)
{
	for(%i = 0; !%b && (%c = String::getSubStr(%this, %i, 1)) != ""; %i++)
		%b = (0 <= String::findSubStr(%that, %c));
	return !%b;
}
Example usage:

Code: Select all

if(!String::onlyContains(%input, "0123456789.")) Client::sendMessage(%client, 0, "Invalid Input!");
Image
perrinoia
Site Admin
Posts: 3732
Joined: Sun Jul 01, 2012 7:18 pm

Re: code help (calling Perrin or crow)

Post by perrinoia »

You're doing it wrong.

The idea was to make a list of characters that ARE allowed...

But if you do want to block those 2 characters, do it like this:
\\
\"
Image
User avatar
DaJ4ck3L
Crow{OZ}
Posts: 3375
Joined: Thu Jul 22, 2010 11:51 pm
Contact:

Re: code help (calling Perrin or crow)

Post by DaJ4ck3L »

i was wondering if \\ would work. i knew \" would work.

also, wouldn't you also need to do all the letters in all caps too?

ABCDEFGHIJKLMNOPQRSTUVWXYZ
Image
perrinoia
Site Admin
Posts: 3732
Joined: Sun Jul 01, 2012 7:18 pm

Re: code help (calling Perrin or crow)

Post by perrinoia »

Code: Select all

if(!String::onlyContains(%input, "0123456789."))
    Client::sendMessage(%client, 0, "Invalid Input!");
else
{
    // place transaction code here.
}
Image
User avatar
DaJ4ck3L
Crow{OZ}
Posts: 3375
Joined: Thu Jul 22, 2010 11:51 pm
Contact:

Re: code help (calling Perrin or crow)

Post by DaJ4ck3L »

you should use tabs or spaces in your formatting.
Image
perrinoia
Site Admin
Posts: 3732
Joined: Sun Jul 01, 2012 7:18 pm

Re: code help (calling Perrin or crow)

Post by perrinoia »

Sorry, I put an exclamation point after the word "return"... This makes the function do the opposite of what I intended.
Image
Post Reply