Home Web Front-end JS Tutorial How to implement mobile phone number selection using jquery_jquery

How to implement mobile phone number selection using jquery_jquery

May 16, 2016 pm 03:47 PM
jquery phone number

The example in this article describes how jquery implements mobile phone number selection. Share it with everyone for your reference. The details are as follows:

Some time ago, I saw that China Unicom’s free combination package was very attractive, so I decided to change my number. However, choosing a number is a very tiring task. I couldn’t choose the number I wanted in the free number list for a long time, so I wrote a script. The analysis of these mobile phone numbers, although not very accurate, at least filtered out the junk numbers. Welcome to make bricks.

The code depends on jQuery. If you are interested, you can refactor it yourself to remove the dependency.

It is recommended to use the debugging tool of Chrome browser to execute.

jquery mobile phone number analysis score:

/*class*/RegexpMatchScorer = function (/*Required RegExp*/reg,
                    /*Required Number*/threshold){
 return function(/*Required char[]*/numberArray){
  if(!!numberArray && !!reg && !!threshold){
   var matcheList = numberArray.join().match(reg);
   if(matcheList != null){
    return matcheList.length * threshold;
   }
  }
  return 0;
 };
}
//分析后8位号码计算号码分数
function analyseNumbers(/*Required String[]*/numberList,
            /*Optional Object{begin,size}*/range,
            /*Optional function(char[])[]*/addtionRules){
 //无4号码计分
 function non4(numberArray){
  var threshold = 4;
  if(!numberArray.inArray("4")){
   return threshold;
  }
  return 0;
 }
 //总数字量加分最高10分
 function numberCount(numberArray){
  var threshold = 10;
  var charCount = uniqueArray(numberArray).length;
  return threshold - ((charCount - 1) * (threshold / (numberArray.length - 1)));
 }
 //重复次数加分
 function adjoinRepeat(numberArray){
  var threshold = 2;
  var score = 0;
  for(var i=1;i<numberArray.length;i++){
   var times = 0;
   if(numberArray[i - 1] == numberArray[i]){
    times++;
    score+=threshold*times;
   }else{
    times=0;
   }
  }
  return score;
 }
 //顺数加分(3位以上)
 function straight(numberArray){
  var threshold = 2.5;
  var sideTimes = 2.5//顺数在两端时2.5倍得分
  var inverseTimes = 0.6
  var score = 0;
  for(var i=2;i<numberArray.length;i++){
   var sTimes = 0;
   var iTimes = 0;
   if((Number(numberArray[i])-1==Number(numberArray[i-1]) && Number(numberArray[i])-2==Number(numberArray[i-2]) && ++sTimes)
    || (Number(numberArray[i])+1==Number(numberArray[i-1]) && Number(numberArray[i])+2==Number(numberArray[i-2]) && ++iTimes)
    ){
    var sc = 0;
    if(i == 2 || i == numberArray.length - 1){
     sc = threshold*sideTimes;//顺数在两端时2.5倍得分
    }else{
     sc = threshold;
    }
    score += sc * (sTimes + iTimes*inverseTimes);
   }else{
    sTimes=0;
    iTimes=0;
   }
  }
  return score;
 }
 //数组去复
 function uniqueArray(parr) {
  function _unique(_arr, i){
   if(i>=_arr.length){
    return;
   }
   if(_arr[i] == _arr[i+1]){
    _arr.splice(i+1,1);
    _unique(_arr,i);
   }else{
    _unique(_arr,i+1);
   }
  }
  var arr=parr.slice().sort();
  _unique(arr,0);
  return arr;
 }
 /*************
 * 计分逻辑
 **************/
 var nonRepeatList = uniqueArray(numberList);
 var scorerList = [non4, numberCount, adjoinRepeat, straight,
          new RegexpMatchScorer(new RegExp("(6|8|9)","g"),0.7)];
 if(!!addtionRules){
  scorerList.concat(addtionRules);
 }
 var scoreTable = [];
 //分析号码
 nonRepeatList.forEach(function(data){
  var score = 0;
  var pn = data.toString();
  if(!!range){
   pn = pn.substr(range.begin, range.size);
  }
  var numberArray = pn.split("");
  scorerList.forEach(function(scorer){
   score += scorer(numberArray.slice());
  });
  //发布分数
  scoreTable.push({"number":data, "score":score});
 });
 return scoreTable;
}

Copy after login

Capture the number list and analyze:

&#65279;//必须在num.10010.com下执行
var url = "http://num.10010.com/NumApp/GoodsDetail/queryMoreNums&#63;callback=&province=51&cityCode=540&rankMoney=&groupKey=65070778&mid=&q_p=51&net=01&roleValue=&preFeeSel=0&keyValue=&Show4GNum=TRUE&q_p=";
var nl = [];
for(var i=1;i<=50;i++){
 var urli = url+i;
 $.get(urli,function(data,status){
  var _json = eval(data);
  for(var j=0;j<(_json.moreNumArray.length/7);j++){
   var idx = j*7;
   var num = _json.moreNumArray[idx];
   nl.push(num);
  }
 });
}
//待上面代码抓取号码完毕后分析号码
//查XX分以上的号码
(function(sc){var x=[];analyseNumbers(nl,{begin:-8,size:8}).forEach(function(d,i){if(d.score>=sc)x.push(d.number+" : "+d.score);}); return x.sort().join("\n");})
(/*score*/10);

Copy after login

I hope this article will be helpful to everyone’s jquery programming design.

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to change the mobile phone number of Amap - Detailed introduction to the method of changing the mobile number of Amap How to change the mobile phone number of Amap - Detailed introduction to the method of changing the mobile number of Amap Mar 20, 2024 pm 08:41 PM

Amap is loved by users for its precise positioning and rich functions. However, during use, sometimes we may need to change the bound mobile phone number to ensure the accuracy of personal information and services. So, how to change the mobile phone number of Amap? The editor has compiled some relevant information, come and take a look with me! How to change the mobile phone number on Amap? Answer: [Amap]-[My]-[Settings Icon]-[Account and Security]-[Mobile Number]-[Change]-[Next Step]. Specific steps: 1. First open the Amap software and enter the home page. We need to click [My] in the lower right corner; 2. Then you can see some related functions in My One Second. Here we click on the upper right corner. [Settings icon] in the corner;

How to check the usage status of mobile phone number? How to check the usage time of mobile phone number? How to check the usage status of mobile phone number? How to check the usage time of mobile phone number? Mar 07, 2024 pm 04:30 PM

With the continuous advancement of mobile communication technology, mobile phone numbers have become an indispensable communication tool in our daily lives. Sometimes, we need to check the usage status of a mobile phone number, such as verifying whether the number is out of service or in arrears. 1. How to check the usage status of mobile phone number? Contacting the operator's customer service is the most direct way to check the usage status of your mobile phone number. Different operators may have different inquiry methods, but this can usually be accomplished by calling the operator's customer service hotline. When talking to customer service staff, you only need to provide the mobile phone number you need to query, and the customer service staff will provide you with detailed usage status information. Therefore, if you want to know the specific situation of a certain mobile phone number, you can get relevant information by calling the operator's customer service hotline. There are

How to change the mobile phone number binding in QQ mailbox - How to change the mobile phone number binding in QQ mailbox How to change the mobile phone number binding in QQ mailbox - How to change the mobile phone number binding in QQ mailbox Mar 04, 2024 pm 03:46 PM

Many friends don’t know how to change the mobile phone number binding in QQ mailbox, so the editor below will share the method of changing the mobile phone number binding in QQ mailbox. Let’s follow the editor to take a look. I believe it will be helpful to everyone. Step 1: First open the QQ mailbox and select the settings above, as shown below. Step 2: Select the account option in the settings, as shown below. Step 3: Choose to log out immediately, as shown below. Step 4: After logging out, choose to register a mobile phone number and email account. Step 5: Choose to register other accounts in the interface that appears, as shown below. Step 6: Use the new mobile phone number according to the prompts and send text messages, as shown below. Step 7: After the sending is completed, the change is successful. The above is the entire content of how to change the mobile phone number binding in QQ mailbox brought to you by the editor. I hope

Detailed explanation of jQuery reference methods: Quick start guide Detailed explanation of jQuery reference methods: Quick start guide Feb 27, 2024 pm 06:45 PM

Detailed explanation of jQuery reference method: Quick start guide jQuery is a popular JavaScript library that is widely used in website development. It simplifies JavaScript programming and provides developers with rich functions and features. This article will introduce jQuery's reference method in detail and provide specific code examples to help readers get started quickly. Introducing jQuery First, we need to introduce the jQuery library into the HTML file. It can be introduced through a CDN link or downloaded

How to remove the height attribute of an element with jQuery? How to remove the height attribute of an element with jQuery? Feb 28, 2024 am 08:39 AM

How to remove the height attribute of an element with jQuery? In front-end development, we often encounter the need to manipulate the height attributes of elements. Sometimes, we may need to dynamically change the height of an element, and sometimes we need to remove the height attribute of an element. This article will introduce how to use jQuery to remove the height attribute of an element and provide specific code examples. Before using jQuery to operate the height attribute, we first need to understand the height attribute in CSS. The height attribute is used to set the height of an element

How to use PUT request method in jQuery? How to use PUT request method in jQuery? Feb 28, 2024 pm 03:12 PM

How to use PUT request method in jQuery? In jQuery, the method of sending a PUT request is similar to sending other types of requests, but you need to pay attention to some details and parameter settings. PUT requests are typically used to update resources, such as updating data in a database or updating files on the server. The following is a specific code example using the PUT request method in jQuery. First, make sure you include the jQuery library file, then you can send a PUT request via: $.ajax({u

jQuery Tips: Quickly modify the text of all a tags on the page jQuery Tips: Quickly modify the text of all a tags on the page Feb 28, 2024 pm 09:06 PM

Title: jQuery Tips: Quickly modify the text of all a tags on the page In web development, we often need to modify and operate elements on the page. When using jQuery, sometimes you need to modify the text content of all a tags in the page at once, which can save time and energy. The following will introduce how to use jQuery to quickly modify the text of all a tags on the page, and give specific code examples. First, we need to introduce the jQuery library file and ensure that the following code is introduced into the page: &lt

Use jQuery to modify the text content of all a tags Use jQuery to modify the text content of all a tags Feb 28, 2024 pm 05:42 PM

Title: Use jQuery to modify the text content of all a tags. jQuery is a popular JavaScript library that is widely used to handle DOM operations. In web development, we often encounter the need to modify the text content of the link tag (a tag) on ​​the page. This article will explain how to use jQuery to achieve this goal, and provide specific code examples. First, we need to introduce the jQuery library into the page. Add the following code in the HTML file:

See all articles