问题
I'm looking for a C# function which returns true if a string contains valid javascript syntax.
For instance:
IsValidJavascript("alert('hello');");
would return true, but
IsValidJavascript("alertXXhelloZ);");
would return false.
回答1:
You'll need to use an interpreter.
You can try Jint which is a Javascript interpreter for .NET.
来源:https://stackoverflow.com/questions/14135783/determine-whether-a-string-contains-valid-javascript-code