Hey 2 fast questions,
i want to forbid some special chars (not everyone!) in a script.
1. QuestionWhat chars?$ % and {
When i try:if (($ isin $2-) || (% isin $2-) || ({ isin $2-)) { return } it dont work!
2. QuestionWhen i write:
if ($2- !isalnum) { return } the scripts returns when someone write something with spaces in it - how can i "fix" this? allow A-Z + 0-9 + Space?
Thank you for the informations
I can only answer one question off the top of my head.
; $chr(36) == $
; $chr(37) == %
; $chr(123) == {
if (($chr(36) isin $2-) || ($chr(37) isin $2-) || ($chr(123) isin $2-)) { return }
If you like
http://www.asciitable.com/index/asciifull.gif or you can find the $chr() for them on your own
//var %x 127 | while (%x) { echo -ag %x - $chr(%x) | dec %x }
That's probably because one or more of those characters are treated as operators/code and not normal characters. To make sure special characters are not evaluated as code, it's a good idea to use $chr.
You can find out what ascii number a character has by using $asc(charater).
Type this for example
//echo -a $asc($)
I'm not sure why $asc({) is not possible, but the number for is 123 anyways.
if ($chr(36) isin $2-) || ($chr(37) isin $2-) || ($chr(123) isin $2-) { return }
that should work
Thank you very much, is working fine!
Also, if you find yourself using a very long serious of if (x isin $2-) && (y isin $2-) && (z isin $2-) ..., you can achieve the same result with if ($count($1-,x,y,z)) or [/b]($countcs($1-,x,y,z))[/b].
You should also consider learning Regular Expressions which opens up a new world with $regex(), $regsub(), $regsubex().
if (!$regex($2-,/[A-Za-z0-9 ]/)) { return } is the equiv to the second question you asked. (though alphanum may also allow _ and - characters, so add them: /[A-Za-z0-9 _-]/)
((I don't need peanut gallery informing me of \w or /i, we're trying to ease him into regex.))