JavaScript RegExp Compatibility in IE

^(?=[\w\-%&?#=]+\d)(?=[\w\-%&?#=]+[a-zA-Z])[\w\-%&?#=]{8,12}$

Designed to meet the following conditions in verifying a new password based on JavaScript,

  • Must contain at least 8-20 characters, including one letter and number
  • It can include only one of the following special characters:%, &, _,?, #, =, -
  • There can be no spaces

With the above expression goog123#was compared in FF3.5. However, this fails in IE6. Does anyone know what's wrong here? Is this a compatibility issue?

JavaScript used to verify compliance

function fnIsPassword(strInput)
{
  alert("strInput : " + strInput);
  var regExp =/^(?=.{0,19}\d)(?=.{0,19}[a-zA-Z])[\w%&?#=-]{8,20}$/;
  if(strInput.length > 0){
     return (regExp.test(strInput));
  }
  return false;
}
alert(fnIsPassword("1231231")); //false 
alert(fnIsPassword("sdfa4gggggg")); //FF: true, false in IE  
alert(fnIsPassword("goog1234#")); //FF: true , false in IE 
+5
source share
2 answers

This is what I found with some sifting.

  • . , .
  • , .

/(?=^[\w%&?#=-]{8,12}$)(?=.+\d)(?=.+[a-zA-Z]).+/
+1

. :

^(?=.{,19}\d)(?=.{,19}[a-zA-Z])[\w%&?#=-]{8,20}$

:

^                    # start-of-string
(?=.{,19}\d)         # look-ahead: a digit within 20 chars
(?=.{,19}[a-zA-Z])   # look-ahead: a letter within 20 chars
[\w%&?#=-]{8,20}     # 8 to 20 chars of your allowed range
$                    # end-of-string
+4

All Articles