RegExp


i have regular expression want validate string.   can work in java 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 returns 0 regardless of input string.

 

what hoping can determine if have valid string such 'thisisvalid' or invalid string such 'this#is#invalid'

 

i have created simple test, can't 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 true, regardless of input string, , inputme.text.search(pattern) returns 0, regardless of input string (including no input string!)

 

clearly don't understand how regex works in flex, seem same result regardless of expression or input string.  of appreciated.

well have solved , share idiosyncrasies of regex flex , java seem work differently:

 

java : "([a-z]|[a-z]|\\*|@|[0-9]|_|$|\\-)*"

 

flex = "(^[a-z,a-z,\\*,@,[0-9],_,$,\\-)*$"   - ^ start of line, followed group of everthing allowed, * 0 many times, $ end of line

 

maybe 1 day come across post , cry joy of thousand camels have found water.



More discussions in Flex (Read Only)


adobe

Comments

Popular posts from this blog

Hur installera Joomla på One.com - Joomla! Forum - community, help and support

removing index.php from URL address - Joomla! Forum - community, help and support

「イメージマップのアンカー名には、...」のエラーが出ないようにしたい