Calculate number of input mobile phone number, verify multi-number, filter duplicate number

Source: Internet
Author: User

HTML code:

<! DOCTYPE html>
<title></title>

<style type= "Text/css" >
#content #contentmain Table Tbody tr td {
border:0;
height:28px;
}
#content #contentmain table{
Text-align:left;
width:100%;
}
. tabel_2{padding:10px;}
. coninf table td{line-height:30px;}
. Coninf Table{width:100%;line-height:25px;border-collapse:collapse;}
. wxw-table{margin-bottom:10px;}
. wxw-table td{border:1px solid #c5c5c5; height:28px;text-align:center;}

</style>
<script src= "Http://code.jquery.com/jquery-1.4.1.min.js" ></script>
<body>
<div id= "Content" >
<div id= "Contentmain" >
<form>
<table class= "Tabel_2" >
<tbody>
&LT;TR style= "border-top:1px solid #ccc;" >
&LT;TD align= "right" valign= "top" style= "padding-top:10px;" > Mobile number:</td>
&LT;TD style= "padding-top:10px;" >
<textarea rows= "3" cols= "class=" Phones "></textarea>
</td>
</tr>
<tr>
<td></td>
&LT;TD class= "Phone_num" >
Total number: <span style= "color:red" >0</span>
</td>
</tr>
<tr>
<td></td>
&LT;TD >
<input type= "button" Name= "value=" Filter Error "class=" querybtn "id=" Wrongnumber ">
<input type= "button" name= "" value= "re-filter" class= "querybtn" id= "Repeatnumber" >
<input type= "button" name= "" value= "two times Filter" class= "querybtn" id= "Doublenumber" >
</td>
</tr>
</tbody>
</table>
</form>
</div>
</div>

</body>

The interface is as follows:

JS Code:

<script type= "Text/javascript" >
Calculate number
var $phone = $ (". Phones");
var ie = jQuery.support.htmlSerialize;
if (IE) {
$phone [0].oninput = Calculatephone;
}else{
$phone [0].onpropertychange = Calculatephone;
}
function Calculatephone () {
if ($ (". Phones"). Val (). IndexOf (",") >=0) {
var strary = $ (". Phones"). Val (). Split (",");
}else{
var strary = $ (". Phones"). Val (). Split ("\ n");
};
$ (". Phone_num"). HTML ("Total number: <span style= ' color:red ' >" +strary.length+ "</span>");
}

Filter the wrong number
$ ("#wrongNumber"). Click (function () {
if ($ (". Phones"). Val (). IndexOf (",") >=0) {
var strary = $ (". Phones"). Val (). Split (",");
}else{
var strary = $ (". Phones"). Val (). Split ("\ n");
};
Wrong_num (Strary)
})
Re-number Filter
$ ("#repeatNumber"). Click (function () {
if ($ (". Phones"). Val (). IndexOf (",") >=0) {
var strary = $ (". Phones"). Val (). Split (",");
}else{
var strary = $ (". Phones"). Val (). Split ("\ n");
};
Uniqueue (strary);
});
Two times filter
$ ("#doubleNumber"). Click (function () {
if ($ (". Phones"). Val (). IndexOf (",") >=0) {
var strary = $ (". Phones"). Val (). Split (",");
}else{
var strary = $ (". Phones"). Val (). Split ("\ n");
};
var arr = uniqueue (strary);
Wrong_num (arr)
})


Re-number filter function
function Uniqueue (array) {
var arr=[];
var m;
while (array.length>0) {
M=ARRAY[0];
Arr.push (m);
Array=$.grep (Array,function (n,i) {
return n==m;
},true);
}
$ (". Phones"). Val (arr);
$ (". Phone_num"). HTML ("Total number: <span style= ' color:red ' >" +arr.length+ "</span>");
return arr;
}
Error number Filter function
function Wrong_num (strary) {
var ismobile=/^ (?: 13\d|15\d|18\d) \d{5} (\d{3}|\*{3}) $/;
var wrong_num=[];
for (Var i=0;i<strary.length;i++) {
Regcellphone =/^ ([1][0-9]{10})? $/;
Falg=strary[i].search (Regcellphone);
if (falg==-1) {
Wrong_num.push (i);
}
}
for (Var j=0;j<wrong_num.length;j++) {
Strary.splice (wrong_num[i],1);
}
$ (". Phones"). Val (strary);
$ (". Phone_num"). HTML ("Total number: <span style= ' color:red ' >" +strary.length+ "</span>");
}
</script>

Calculate number of input mobile phone number, verify multi-number, filter duplicate number

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.