I'm trying to find phone number and mobile number from an array with jquery.
jQuery:
var data = $('#PhoneLabel').text();
var array = data.split(', ');
$.grep(array, function (item, index) {
if (item.charAt(0) === '0' && item.charAt(1) === '9') {
var mob = item;
$('#UserMobMenuSMS').attr('href', 'sms:' + mob);
$('#UserMobMenuTel').attr('href', 'tel:' + mob);
alert('its mobile');
} else if (item.charAt(0) !== '0' && item.charAt(1) !== '9') {
$('#UserMobMenuSMS').addClass('disableUserMenuMob');
$('#UserMobMenuSMS').attr('href', '#');
alert('there is no mobile');
} else {
var phone = item;
$('#UserMobMenuTel').attr('href', 'tel:' + phone);
alert('its phone');
}
});
if number start with 09 it is mobile number and else it's phone number. and there is 3 forms in html:
first, only phone number:
Not Working
<span id="PhoneLabel" class="GlobalTelColor">021-88915907 , 021-88915907</span>
second, phone number and mobile number:
Working good
<span id="PhoneLabel" class="GlobalTelColor">09127007008 , 021-55293301-6 , 021-55293003</span>
third, only mobile number:
Working good
<span id="PhoneLabel" class="GlobalTelColor">09195328272</span>
the problem is in first form, if there is no mobile number in array, I want to use phone number in #UserMobMenuTel and disable #UserMobMenuSMS with disableUserMenuMob class. I mean when there is no mobile number UserMobMenuSMS should get disableUserMenuMob class, but it's not working, i guess i used wrong method in this case, is there any better way and solution?.
please check out the JSFiddle Demo.