aleroot
aleroot

Reputation: 72646

Java detect if a string is a valid JS script

I want to detect if a string is a valid javasript code for pass it for the evaluation of rhino engine, now i'm assuming that the string is a javascript script with this simple statement :

if(jsString.trim().endsWith(";")) {
//Evaluate with Rhino
}

Is there a better way for figure out if a string is a valid JS script ?

What is the best way ?

Upvotes: 2

Views: 1457

Answers (1)

BGerrissen
BGerrissen

Reputation: 21690

You could utilise something like: http://code.google.com/p/jslint4java/

In any case, you want to run the string through JSLint.

Upvotes: 1

Related Questions