5

How would I create 3 more scripts with regex that would check if the android is a certain version. I provided a sample ua header from a android version 2.2.

scripts needed

  • android 2.2.3 and below check

  • android 2.3 to 2.3.7 check

  • android 3.0 and above check

android ua string example:

Mozilla/5.0 (Linux; U; Android 2.2; en-us; Nexus One Build/FRF91) AppleWebKit/533.1     (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1

based off of this script

var ua = navigator.userAgent.toLowerCase();
var isAndroid = ua.indexOf("android") > -1;

1 Answer 1

6

Just off the top of my head, how about something like this:

var isAndroid = /android/i.test(ua);
var isGingerbread = /android 2\.3/i.test(ua);
var isHoneycombOrNewer = /android [3-9]/i.test(ua);
var isFroyoOrOlder = isAndroid && !isGingerbread && !isHoneycombOrNewer;
Sign up to request clarification or add additional context in comments.

1 Comment

Oh sorry, I just realized you were doing indexOf instead of actual regex. Let me update my answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.