3 Replies Latest reply on Sep 14, 2010 8:25 AM by rtalton

    RegExp

    Agent-96 Level 1

      I have a regular expression from which I want to validate a String.   I can get this to work in Java but not in Flex.

       

      The Flex (Actionscript) code is:

       

      var stringToCheck:String = "someString";

      var pattern:RegExp =  new RegExp("([A-Z]|[a-z]|\\*|@|[0-9]|_|$|\\-)*");
      trace(stringToCheck.search(pattern));

       

      This always returns 0 regardless of the input string.

       

      What I am hoping is that I can determine if I have a valid string such as 'thisIsValid' or an invalid string such as 'this#is#invalid'

       

      I have also created another simple test, which I can't get to work:

       

      var pattern:RegExp =  new RegExp("([A-Z])*");
      if(pattern.test(inputMe.text)) {
          trace("MATCH " + inputMe.text);           
      } else {
          trace("NO MATCH " + inputMe.text);   
      }

      trace(inputMe.text + " - " + inputMe.text.search(pattern));

       

      pattern.test is always true, regardless of the input string, and inputMe.text.search(pattern) always returns 0, regardless of input string (including no input string!)

       

      Clearly I don't understand how RegEx works in flex, as I always seem to get exactly the same result regardless of expression or input string.  Any help of this would be much appreciated.