ID:176525
 
Okay, say I have a string, such as var/mybad = "DinkyDonk"
How can I make sure that the string only contains certain characters, such as A-Z. Can I treat it as a list? Ex, mybad[1] = "D" mybad[2] = "i" etc.?
Maybe findtext() is what you are looking for.

You can look for characters that you don't want in there such as numbers or dashes. You can put them in a list like so:

var/list/invalid = list("0","1","2","3","4","5","6","7","8","9","-")

Then Check if a text string contains any of those characters:

mob/proc/Check(string)
for(var/X in invalid)
if(findtext(string,X))
src << "Error:[X] not allowed"
return

Hope ive been helpful.
In response to Soori-99
Yes, I took a look at that... but no. I need to filter valid characters, instead of invalid. I've found a method, and I'm writing code right now. Using the copytext to copy it letter by letter to a list... then I can individually check it... I've got it all in my head, lol. Wonder how many Errors I'll get.
[Edit]
HOORAY! It works perfectly... I'm testing in a verb right now, here it is, try it if you want:
Test()
var/mytext = "ABCDEFGHIJKL!M"
var/list/validchar = list("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O")
var/temptext = ""
var/newtext = ""
world << mytext
var/cur = 1
for(cur=1, cur <= length(mytext), cur++)
temptext = copytext(mytext,cur,cur+1)
if(validchar.Find(temptext) != 0)
newtext += temptext
world << newtext

As you see, the character "!" is not on the valid character list, and is stripped. That ought to keep characters like ~ or Å away!