F
François R
I use a regular expression and the user give the pattern it is build
with.
I would like to alert him when the syntax of the pattern is wrong.
if template is the variable that old the pattern, I have tried:
try {
var t = new RegExp(template);
} catch(e) {
window.alert("Bad syntax in regex " + e.message);
}
or variations around
try {
eval( "var t = new RegExp(" + template + ");");
} catch(e) {
window.alert("Bad syntax in regex " + e.message);
}
without success. Either the alert is always given or it never appears.
Thanks for any help on how to do this
François
with.
I would like to alert him when the syntax of the pattern is wrong.
if template is the variable that old the pattern, I have tried:
try {
var t = new RegExp(template);
} catch(e) {
window.alert("Bad syntax in regex " + e.message);
}
or variations around
try {
eval( "var t = new RegExp(" + template + ");");
} catch(e) {
window.alert("Bad syntax in regex " + e.message);
}
without success. Either the alert is always given or it never appears.
Thanks for any help on how to do this
François