ID:2416371
 
hello how are you? How can I make a dream maker so that one can not place symbols like> <in their names?
Pass the name through a function first to check the characters.

Create a list in the function that contains the letters/numbers/symbols that you want to allow in names.

Check each character in the name in a loop to make sure its in that list, and then if the character isn't in the list then you do whatever you want to do with it.

take your name the user picks.
var/usrname = input(usr,"Enter a name") as null|text
if(!usrname) return
usrname = TxtCheck(usrname)


run it through the function...

    TxtCheck(txt)

//This proc is running with the idea of trimming out the unwanted characters.
//So someone with the name 'Ice-Fire-2050' would have that changed to 'IceFire2050'

//Creates a list of acceptable characters.
//This list only allows letters and numbers. No characters or spaces.
//You can add other entries if you want to allow other symbols.
var/list/T = list("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9")

//Creates your vars to use in your loop.
var/counter = length(txt)
var/count = 1
//This var is where we'll build the adjusted name.
var/ntxt = ""

//This loop will run 1 time for each character in the name.
while(count<=counter)

var/S

//Pulls 1 character out of the name and stores it as var/S
if(count!=counter) S = copytext(txt,count,count+1)
else S = copytext(txt,count)

//Checks to make sure the character stored in var/S is in the list we have above.
//If it is, it adds that character to the var/ntxt above, if not then it ignores it and moves on.
for(var/V in T) if(findtext(V,S)) ntxt += "[S]"


count++

//Once the loop is finished, it returns the completed new name back to whatever called it.
return ntxt

html_encode(TEXT)

Will encode the html so that it can't be displayed in the browser or output. You'll simply see the plain html.

You can also do this.

var list/_sanitize = list("<",">","/")

proc/SanitizeText(string)
for(. in global._sanitize)
string = replacetext(string,.,"")
return string
You probably don't want to use . that way, if the loop fails for any reason that causes the proc to not reach the end the proc will return the value that was assigned to . instead of the string variable. (It probably won't be an issue in this case, but it's not a good habit to get into for this reason). If you want to use . in this case you'd probably want to do it the other way around.

. = string
for(var/item in _sanitize)
. = replacetext(.,item,"")


This way doesn't require a return at the end, and will give you a string even if something goes wrong.