Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    How to check if the string is a regular expression or not

    Hi team.
    I have a string in TextItem.
    How I can check if the string is a regular expression or contains regular expression or it is a normal string?(In client side )
    Can you give me some idea.

    #2
    https://stackoverflow.com/questions/...ssion/17251034

    Comment


      #3
      Thanks for your reply.
      I got to use RegEx.
      In that code is not work ,Can you tell me what is miss?

      import com.smartgwt.client.widgets.form.validator.CustomValidator;

      public class StringIsRegexValidator extends CustomValidator {

      /*
      * (non-Javadoc)
      *
      * @see
      * com.smartgwt.client.widgets.form.validator.CustomValidator#condition(java.
      * lang.Object)
      */
      @Override
      protected boolean condition(Object value) {

      if (value == null || value.toString().isEmpty()) {
      this.setErrorMessage("is Empty");
      return false;//Maybe Is not necessary here?
      }
      final String pattern = value.toString().trim();

      if (!StringIsRegexValidator.checkRegExp(pattern)) {
      this.setErrorMessage("is not Regex");
      return false;
      }
      return true;
      }
      public static native boolean checkRegExp(String pattern) /*-{
      try {
      $RegExp(pattern);
      return true;
      } catch(e) {
      return false;
      }
      }-*/;
      }

      Comment

      Working...
      X