Don't.
Either
Use conditional comments instead. That's the proper way to target versions of IE.
Output this directly to the web page:
<!-- [if lte IE 6]
<div id="ie6div">This page may not behave correctly in your browser. I suggest you <a href="http://browserupdate.org">update</a> your browser.</div>
-->
Or
Use the browser update javascript:
<script type="text/javascript">
var $buoop = {}
$buoop.ol = window.onload;
window.onload=function(){
if ($buoop.ol) $buoop.ol();
var e = document.createElement("script");
e.setAttribute("type", "text/javascript");
e.setAttribute("src", "http://browser-update.org/update.js");
document.body.appendChild(e);
}
</script>
It's generally agreed that parsing the User-Agent string is evil.