@Pinecone: That looks like a very simple implementation, although I'd suggest you could optimize that code by breaking out of the loop as soon as you found an invalid character:
code:
for (j=0; j<Msg.length; j++) if ((Msg.charCodeAt(j) < 40) || (Msg.charCodeAt(j) > 57)) {
Valid = false;
break;
}
@Spunky: Indeed, you can simply strip out all alphabetical characters and other possibly malicious characters. However, I'd suggest you to improve your stripping algorithm then: instead of looping through the whole array everytime !calc is received, you could create one single RegExp at start-up formed by a single loop which will strip all unwanted characters:
code:
var iChars = array("!", "£", "\\$", "\&", "\\?", "\>", "\<", ",", "\\.", "@", "\'", ":", ";", "\\[", "\\]", "=", "\\|", "`", "¬", "\\\\", "\"");
var reStrip = new RegExp("[a-z" + iChars.join("") + "]+", "gi");
/* ... */
Message = Message.substr(6);
Message = Message.replace(reStrip, "");
try{
/* ... */
And what if you'd want to extend such a script and make things like sin(60), cos(60), sqrt(64) work? Well, good luck to both of you if you're looking to extend your scripts.