As other people have already pointed out, feature detection is preferable to checking a specific browser. One reason is that the user agent string can be changed. Another reason is that the line may change and break your code in newer versions.
If you still want to do this and test any version of Safari, I would recommend using this
var isSafari = navigator.vendor && navigator.vendor.indexOf('Apple') > -1 && navigator.userAgent && navigator.userAgent.indexOf('CriOS') == -1 && navigator.userAgent.indexOf('FxiOS') == -1;
This will work with any version of Safari on all devices: Mac, iPhone, iPod, iPad.
Edit
To check in your current browser: https://jsfiddle.net/j5hgcbm2/
Edit 2
Updated according to Chrome docs to correctly detect Chrome on iOS
It is worth noting that all browsers on iOS are just wrappers for Safari and use the same engine. See Bfred.it comment on his own answer in this thread.
Edit 3
Updated according to Firefox docs to correctly detect Firefox on iOS
qingu Jul 30 '15 at 19:20 2015-07-30 19:20
source share