实现网页中的搜索输入框效果 onfocuse onblur js 验证手机号 座机区号

来源:互联网 发布:最火的中文编程 编辑:程序博客网 时间:2024/04/28 12:13

  function cleartxt() {
            var value = document.getElementById("txtTest").value;
            if (value == "在这里搜索")  //聚焦时,如果文本框为初始值,则清空
                document.getElementById("txtTest").value = "";
        }
        function resettxt() {
            var value = document.getElementById("txtTest").value;
            if (value == "" || value == null)  //失焦时,如果文本框为空,则给初始值
                document.getElementById("txtTest").value = "在这里搜索";
        } 


<input type="text" name="passwordtwo" class="search" value="搜索" onfocus="if(this.value=='搜索') this.value='';this.style.color='#333'; return true;"

                                onblur="if(this.value=='') this.value='搜索'; this.style.color='#999'; return true;"
                                id="srch1" style="color: rgb(153, 153, 153);">
                                <asp:TextBox ID="txtTest" runat="server"
                                    BorderStyle="Double" Width="223px" ForeColor="DimGray" value="在这里搜索" onfocus="cleartxt()"

                                    onblur="resettxt()"></asp:TextBox>




上边是效果图。其实需要提示的是电话号码。不过要做成搜索输入框的效果。啊哈哈哈哈。网络就是好。。。


1、最新的电话号码段:

移动:134(1349除外)135 136 137 138 139

147
150 151 152 157 158 159

182 183 184 187 188

联通: 130 131 132 
155 156 
185 186 
145

电信:133 153 177 180 181 189

2、电话号码正则:

固话:([0-9]{3,4}-)?[0-9]{7,8}

手机:^((\+?86)|(\(\+86\)))?(13[012356789][0-9]{8}|15[012356789][0-9]{8}|18[02356789][0-9]{8}|147[0-9]{8}|1349[0-9]{7})$

3、校验函数

?
1
2
3
4
5
6
7
8
9
10
11
function checkTel(){
    var isPhone = /^([0-9]{3,4}-)?[0-9]{7,8}$/;
    var isMob=/^((\+?86)|(\(\+86\)))?(13[012356789][0-9]{8}|15[012356789][0-9]{8}|18[02356789][0-9]{8}|147[0-9]{8}|1349[0-9]{7})$/;
    var value=document.getElementById("ss").value.trim();
    if(isMob.test(value)||isPhone.test(value){
        returntrue;
    }
    else{
        returnfalse;
    }
    }


   电话号码正则表达式(支持手机号码,3-4位区号,7-8位直播号码,1-4位分机号) ((\d{11})|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$) 

匹配格式: 
11位手机号码 
3-4位区号,7-8位直播号码,1-4位分机号 
如:12345678901、1234-12345678-1234 







"^\d+$"  //非负整数(正整数 + 0)  
"^[0-9]*[1-9][0-9]*$"  //正整数  
"^((-\d+)|(0+))$"  //非正整数(负整数 + 0)  
"^-[0-9]*[1-9][0-9]*$"  //负整数  
"^-?\d+$"    //整数  
"^\d+(\.\d+)?$"  //非负浮点数(正浮点数 + 0)  
"^(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*))$"  //正浮点数  
"^((-\d+(\.\d+)?)|(0+(\.0+)?))$"  //非正浮点数(负浮点数 + 0)  
"^(-(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*)))$"  //负浮点 
数  
"^(-?\d+)(\.\d+)?$"  //浮点数  
"^[A-Za-z]+$"  //由26个英文字母组成的字符串  
"^[A-Z]+$"  //由26个英文字母的大写组成的字符串  
"^[a-z]+$"  //由26个英文字母的小写组成的字符串  
"^[A-Za-z0-9]+$"  //由数字和26个英文字母组成的字符串  
"^\w+$"  //由数字、26个英文字母或者下划线组成的字符串  
"^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$"    //email地址  
"^[a-zA-z]+://(\w+(-\w+)*)(\.(\w+(-\w+)*))*(\?\S*)?$"  //url  
/^13\d{9}$/gi手机号正则表达式


public static bool IsValidMobileNo(string MobileNo) 
  { 
   const string regPattern = @"^(130|131|132|133|134|135|136|137|138|139)\d{8}$"; 
   return Regex.IsMatch(MobileNo, regPattern); 
  }


正则表达式--验证手机号码:13[0-9]{9} 
实现手机号前带86或是+86的情况:^((\+86)|(86))?(13)\d{9}$ 
电话号码与手机号码同时验证:(^(\d{3,4}-)?\d{7,8})$|(13[0-9]{9})  
提取信息中的网络链接:(h|H)(r|R)(e|E)(f|F)  *=  *('|")?(\w|\\|\/|\.)+('|"|  *|>)?   
提取信息中的邮件地址:\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*   
提取信息中的图片链接:(s|S)(r|R)(c|C)  *=  *('|")?(\w|\\|\/|\.)+('|"|  *|>)? 
提取信息中的IP地址:(\d+)\.(\d+)\.(\d+)\.(\d+)     
提取信息中的中国手机号码:(86)*0*13\d{9}     
提取信息中的中国固定电话号码:(\(\d{3,4}\)|\d{3,4}-|\s)?\d{8}     
提取信息中的中国电话号码(包括移动和固定电话):(\(\d{3,4}\)|\d{3,4}-|\s)?\d{7,14}     
提取信息中的中国邮政编码:[1-9]{1}(\d+){5}     
提取信息中的中国身份证号码:\d{18}|\d{15}     
提取信息中的整数:\d+     
提取信息中的浮点数(即小数):(-?\d*)\.?\d+     
提取信息中的任何数字  :(-?\d*)(\.\d+)?   
提取信息中的中文字符串:[\u4e00-\u9fa5]*     
提取信息中的双字节字符串  (汉字):[^\x00-\xff]* 

证电话区号的正则表达式:
(0[1-9]{2,3})



0 0
原创粉丝点击