Either a client side or server side solution would be ok.
For a client side solution I'd like to confirm that, say :
var a = "function foo { var t='ok'; alert(t); }"
is valid, or for a server side solution that
String a = "function foo { var t='ok'; alert(t); }"
is valid.
Thanks
Neither is client-side or server-side.
The first vaguely resembles JavaScript, and the second vaguely resembles
Java.
Each has both client-side and server-side forms.
But does your crosspost mean that you really are looking for a solution
in either language?
Stewart.
--
My e-mail is valid but not my primary mailbox, aside from its being the
unfortunate victim of intensive mail-bombing at the moment. Please keep
replies on the 'group where everyone may benefit.
But the language can not be server-side Javascript (old netscape Livewire).
The following sample code should provide a check for valid Javascript
syntax.
Note that it could be greatly simplified if you are able to assume the
browser supports try/catch. If not, and the browser (e.g., IE 4.0,
Navigator 3.0) supports window.onerror, it is used in an attempt to
give a slightly more graceful failure. In the latter case,
window.onerror could be further exploited to provide support for the
validation.
validate = null;
validateFunctionText =
' try {'
+ ' var f = new Function(str);'
+ ' return "Validated OK";'
+ ' }'
+ ' catch (e) {'
+ ' return "Validation failed: "+(e.description '
+ ' || e.message || "");'
+ ' }';
function catchError(msg) {
return ! alert("Failed to create validator: "+(msg || "")) ;
}
if (typeof window.onerror != "undefined") {
onerrorSave = window.onerror;
window.onerror = catchError;
validate = new Function("str", validateFunctionText);
window.onerror = onerrorSave;
}
else validate = new Function("str",validateFunctionText);
// Test
var a = "function foo { var t='ok'; alert(t); }" ;
if(validate) alert( validate(a)) ;
else alert("Unable to validate Javascript");
../rh
>
> Thanks