1

I have been able to detect if browser is IE8 and get the version out of the user agent string using this code :

public boolean isValidIE(String strAgent) {
    if (1==1){
        return true;
    }
    Pattern pattern = Pattern.compile(".*\\sMSIE\\s(\\d{1,}\\.\\d{1,})[^;]*;.*");

    Matcher match = pattern.matcher(strAgent);
    if(!match.matches()) {
        return false;
    }
    String ver = match.group(1);
    float version = Float.parseFloat(ver);
    if(version >= 8) {
        return true;
    }
    return false;
}

Now I have to upgrade this to work with IE11 but I think I'll have to add another regex string to determine IE11, is there any way I can achieve this need using only one regex string?

NeedAnswers
  • 1,411
  • 3
  • 19
  • 43

2 Answers2

0

You could try this one :

(?:\b(MS)?IE\s+|\bTrident\/7\.0;.*\s+rv:)(\d+)

Source : https://stackoverflow.com/a/19987665/1203816

It should match every version of IE, not only 8 and 11. The version numbers are shifted, so IE 8 is 4, and consequently IE would by 7.

Community
  • 1
  • 1
krestano
  • 136
  • 3
0

I don't think a browserdetection with the user-agent is a good idea anymore. An IE11 will behave more like a webkit, than an IE8.

If you use special Internet-Explorer code, you will need to rewrite it to use feature detection instead of browser detection.

The IE11 in IE10 compat mode is not campatible to an IE10 (there are some methonds in JavaScript missing). In this case for example,, you browserdetection will fail.

Christian Kuetbach
  • 15,850
  • 5
  • 43
  • 79