/** * jQuery mobiletype * * @param MobileNumber * ReturnLanguage(zh or en) * @returns mobiletype * * Example Code <code> * $.mobiletype("13810095555", "zh"); * </code> Result <code> * "移动" * </code> * * @author StyleAnt [ styleant.tian@gmail.com ] * * version 1.0 */ (function($) { var mobiledata = [ { type : 'ChinaMobile', title : [ 134, 135, 136, 137, 138, 139, 150, 151, 152, 157, 158, 159, 187, 188, 184 ], name : '移动' }, { type : 'ChinaUnicom', title : [ 130, 131, 132, 155, 156, 185, 186 ], name : '联通' }, { type : 'ChinaTelecom', title : [ 133, 153, 180, 189 ], name : '电信' } ]; var search = function(k, k1) { var json = eval(mobiledata); for ( var i = 0; i < json.length; i++) { var mobile_title = json[i].title; for ( var j = 0; j < mobile_title.length; j++) { if (mobile_title[j] == parseInt(k)) { if (k1 == 'zh') { return json[i].name; } else { return json[i].type; } } } } }; $.extend({ mobiletype : function(string, string) { if (string.match('^[0-9]*[1-9][0-9]*$') && string.length > 3) { var k = string.substring(0, 3); return search(k, string); } else { return "Unknow"; } } }); })(jQuery);
调用方法:$.mobiletype("13810095555", "zh");
PS:第一次写jquery插件,写得不好,望高手手下留情,呵呵,谢谢!