4

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
  • Well run it through interpreter. Commented Jan 3, 2013 at 9:08

1 Answer 1

6

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

Sign up to request clarification or add additional context in comments.

2 Comments

nice solution which does not seem to force the client to actually "execute" the js code to validate, +1
I too need something similar but mine is a java function, any port/alternate of above mentioned solution in java?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.