Is there an existing function (or perhaps someone wrote some existing code) to validate in a JS function that the text passed is valid PCRE? I’ve been Googling like crazy but the closest thing I’ve been able to find is just “PCRE_JAVASCRIPT_COMPAT” (which is a PCRE compatibility flag) or discussions about validating input in both PHP and Javascript.
The closest thing I’ve seen to Javascript REGEX validation is:
try {
"".match(regex);
return true;
} catch (e) {
return false;
}
This does not take into account differences between JS (ECMA) regular expressions and PHP (PCRE) regular expressions – that’s obviously an issue, but I’ve not found a clear discussion of the differences between the two.
Any help please?
Quick & Dirty AJAX code to check against PHP:
Javascript:
PHP: