Here are 3 ways to detect mobile...
- Community Supported Browser Sniffing through the WURFL project
- Custom Browser Sniffing (what you're doing now, quite common though not considered a best practice)
- Detecting through feature support.
Option 1: Will probably get you the best overall support if you're really looking to support non-smartphones. This is done on the backend by checking the user agent against a massive database of known devices that is regularly updated by the community. Since it does not rely on JavaScript, it's probably the best way to support absolutely everybody.
Option 2: People on non-smartphones know that surfing web on them sucks. They are therefor less likely to use them for the web. As a percentage of traffic, the percentage of people you will be missing by using detection in JavaScript is probably not worth talking about. For the sites that I have seen, it's been less than 2% on BlackBerry 5 or older and less than 1% for anything else that wasn't Android, iOS, or BlackBerry 6+. I've supported this method of detection before and here is how I did it. Note the allowance for any webkit based option provided the screen is small (isUnknownMobile). This is an attempt at future proofing until such a platform could gain enough traction to be called out.
<script>
var agent = navigator.userAgent;
var isWebkit = (agent.indexOf("AppleWebKit") > 0);
var isIPad = (agent.indexOf("iPad") > 0);
var isIOS = (agent.indexOf("iPhone") > 0 || agent.indexOf("iPod") > 0);
var isAndroid = (agent.indexOf("Android") > 0);
var isNewBlackBerry = (agent.indexOf("AppleWebKit") > 0 && agent.indexOf("BlackBerry") > 0);
var isWebOS = (agent.indexOf("webOS") > 0);
var isWindowsMobile = (agent.indexOf("Windows Phone OS") > 0);
var isSmallScreen = (screen.width < 767 || (isAndroid && screen.width < 1000));
var isUnknownMobile = (isWebkit && isSmallScreen);
var isMobile = (isIOS || isAndroid || isNewBlackBerry || isWebOS || isWindowsMobile || isUnknownMobile);
var isTablet = (isIPad || (isMobile && !isSmallScreen));
function mobileRedirect(mobileView){location.replace((mobileView)?mobileView:"/mobile/index.jsp");}
</script>
Option 3: Feature detection is probably a far more future proofed way of testing if a client is mobile. Consider using the Modernizr Project to see what features are supported. For example, if the device has a small screen and supports canvas, or if it has a touch interface, they're probably mobile. Again, this is front-end based detection and relies on JavaScript.
If you're really looking to redirect EVERYONE who is mobile, the WURFL project is your best bet.