I try to check the str validation by /^$/.test() method, and want it to return false after discovering there is
str = "Abc0Z"; //string to be tested
regex_pattern = /[^0-9A-Z]/; //if 0-9 and A-Z were not found in string,
// .test() returns true
//otherwise, returns false
if(regex_pattern.test(str)){
//do something
}else{
//do other things
}
In the above example, it returns true even when 0-9 And A-Z are found, is that the syntax of /[^Reg]/ is not supported in the Javascript Reg.text(test_string) method?
Can someone explain the mechanism behind, so the method return true other than false?
Because of the failure,I try the following to obtain the same purpose:
str = "Abc0Z"; //string to be tested
regex_pattern = /[0-9A-Z]/; //if 0-9 and A-Z were found in string, .test() return true
//otherwise, returns false
if(regex_pattern.test(str) == false){
//do something
}else{
//do other things
}
And it works as I want it to. But I really don't know why /[^0-9A-Z]/ is not work as expected...Is that any mistake of my Regex syntax or any other reasons to make it work unsuccessful?
Thanks for any help!