Javascript - Regex Matching Devices On User Agent
I'm using the PHP class 'Mobile Detect' to detect user device type (tablet/phone) however I also want to detect certain devices in javascript. Can someone help me convert the follo
Solution 1:
Are you looking for something like this?
var user_agent = navigator.userAgent;
var samsung = /Galaxy.*Tab|SAMSUNG.*Tablet|Galaxy.*Tab|Android.*GT-/i;
// if statement checking samsung regex against user agentif (samsung.test(user_agent)) {
// This is a samsung mobile device
}
var nexus = /^.*Android.*Nexus(((?:(?!Mobile))|(?:(\s(7).+))).)*$/i;
// if statement checking nexus7 regex against user agentif (nexus.test(user_agent)) {
// This is a nexus mobile device
}
Or did you actually want help fixing malfunctioning / incomplete regular expressions?
If you need a solid regular expression, I suggest you go play around at txt2re.com it's the best regular expression generator I know of.
Post a Comment for "Javascript - Regex Matching Devices On User Agent"