Wednesday 15 July 2015

javascript - How to check if the input string is a valid Regular expression? -


How do you check in JavaScript, if the string is the proper regular expression that will compile?

You can try try / catch and RegExp constructor :

  var isValid = true; Try {New RegExp ("the_regex_to_test_goes_here"); } Hold (e) {isValid = false; } (IsValid) Warning ("Invalid Regular Expressions");    

No comments:

Post a Comment