Is there a way to parse javascript code server side? Like a way to pass to a javascript engine the code to be eval'ed within the server and get a result back? The reason I'm wondering is it would be nice to write my validation rules for fields once and in once language. Since javascript can be disabled on the clientside it cannot be relied on for validation. However, if I have a serverside parser I can pass the code to be validated over to the js parser, have it return the results of the validation and proceed based on this.

Advantage -> the coding should be faster to write since validations only need to be written once, and DRY methodology is preserved by having those validations expressed only once. Disadvantage -> This will be likely be slower than handling the validation purely in PHP, but unless the performance hit is sizable I'm willing to live with it on the application I'm planning on applying this to.


(The reason this post is in PHP and not in Javascript is I intend to call the js parser from PHP and the majority of the code will be PHP. That is, I want to call a javascript parser from a PHP environment).