shamp00
shamp00

Reputation: 11326

Determine whether a string contains valid javascript code

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.

Upvotes: 4

Views: 2291

Answers (1)

Blachshma
Blachshma

Reputation: 17395

You'll need to use an interpreter.
You can try Jint which is a Javascript interpreter for .NET.

Upvotes: 6

Related Questions