3

I have a form generator that uses (perl compatible) regexes for ther backend validation. Since the whole form is being dynamically generated it was fairly trivial to add a bit of jquery and then use the same regexes to validate on the client side pre submission.

However, some of the time the regexes don't behave themselves in Javascript, I am suspecting that either they are not being properly escaped, or contain illegal characters etc. Anyone knows a way of making sure that the same regex will work on both platforms?

Meep3D
  • 3,803
  • 4
  • 36
  • 55

2 Answers2

2

Read about specific implementation details for Regular Expressions in Javascript.

JavaScript implements Perl-style regular expressions. However, it lacks quite a number of advanced features available in Perl and other modern regular expression flavors

For one thing, the / character denotes the beginning and end of a regex in Javascript, so you might need to escape it, but that depends on how you're instantiating the regular expression in Javascript (with the literal notation or the RegExp class).

Rahul
  • 12,181
  • 5
  • 43
  • 64
-3

PHP preg_* functions and JavaScript both use Perl-compatible regular expressions. In principle, they should support the same set of regular expressions.

You really should give some examples of what is not working, because it is very likely that your problem is due to escaping/string handling.

rix0rrr
  • 9,856
  • 5
  • 45
  • 48
  • Well I wasn't aware that there's a C library with that name, and I'm not saying browsers use that particular library, but the regular expressions in JavaScript are definitely Perl-compatible. – rix0rrr Jul 15 '09 at 15:50
  • 1
    No they aren’t. One example: JavaScript doesn’t support look-behind assertions. For more examples, see http://www.regular-expressions.info/javascript.html – Gumbo Jul 15 '09 at 17:16