Link to home
Start Free TrialLog in
Avatar of tunhien
tunhien

asked on

How to check a regular expression string is valid or not?

I try to write a program that allow people to input an regular expression and then I will use it to excute. But If the input string is not a valide regular expression then when execute it, the executer will through error.
It's not good. And I wanna check the valide of it!

So please show me how to do that!
Thanks so much!
Avatar of 0h4crying0utloud
0h4crying0utloud


Maybe there is an easier way....  try using a  "try .. catch..."  block when you create the regex object:

try {

var re = new RegExp(document.yourFormName.regexTextBox.value);
}
catch {
  alert("that's some funky regex dude.");
}
ASKER CERTIFIED SOLUTION
Avatar of 0h4crying0utloud
0h4crying0utloud

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial