-1

Are javascript and java regular expression the same? Can we use the same regular expression at both places to validate both on server side client?

3
  • Regex is regex. Should work the same way. :) Commented Feb 23, 2016 at 7:20
  • can you share some scenarios so that we can give hints. its too broad to answer. Commented Feb 23, 2016 at 7:21
  • 1
    Possible duplicate of Differences in regex patterns between JavaScript and Java? Commented Feb 23, 2016 at 7:21

1 Answer 1

2

Is javascript and java regular expression are same ?

They're very similar, but they're not the same, as a brief glance at reference material makes clear, say MDN's article on JavaScript regular expressions vs. Java's Pattern class documentation. For one thing, Java's regex supports various Posix character classes which JavaScript regrettably does not.

Can we use same regular expression at both place to validate server side validation and client side validation ????

That's actually a different question, because you can run JavaScript on the JVM, so you can use the exact same expression in your client-side JavaScript code and your server-side code running on the JVM, using Rhino or Nashorn, which are JavaScript scripting engines for the JVM. You can compile JavaScript code to Java bytecode and use it like a Java class.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.