code: public void checkValid(CharSequence literal)
              throws DatatypeException {
          // TODO find out what kind of thread concurrency guarantees are made
          ContextFactory cf = new ContextFactory();
          Context cx = cf.enterContext();
          RegExpImpl rei = new RegExpImpl();
          String anchoredRegex = "^(?:" + literal + ")$";
          try {
              rei.compileRegExp(cx, anchoredRegex, "");
          } catch (EcmaError ee) {
              throw newDatatypeException(ee.getErrorMessage());
          } finally {
              Context.exit();
          }
      }
docs: Checks that the value compiles as an anchored JavaScript regular expression.
  @param literal the value
  @param context ignored
  @throws DatatypeException if the value isn't valid
  @see org.relaxng.datatype.Datatype#checkValid(java.lang.String, org.relaxng.datatype.ValidationContext)