首页 > 其他分享 >Auto format Phone number

Auto format Phone number

时间:2023-11-09 12:34:58浏览次数:35  
标签:pp Phone Auto number substring phone length txt d2

 

Phone number (123)456-7890

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="TEST.aspx.vb" Inherits="TEST" %>   
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">    
<html xmlns="http://www.w3.org/1999/xhtml">    
<head runat="server">    
    <title>Untitled Page</title>    
    <script language="javascript" type="text/javascript"> function ValidatePhone(txt){   
 var phone=txt.value;    
 if(phone.length==3){    
    var pp=phone;    
    var d4=phone.indexOf("(");    
    var d5=phone.indexOf(")");    
    if(d4==-1){    pp="("+pp;    }    
    if(d5==-1){    pp=pp+")";    }    
    txt.value=pp;    
    }    
 if(phone.length>3){    
    d1=phone.indexOf('(');    
    d2=phone.indexOf(')');    
    if (d2==-1){    
        l30=phone.length;    
        p30=phone.substring(0,4);    
        p30=p30+")";    
        p31=phone.substring(4,l30);    
        pp=p30+p31;    
        txt.value=pp;    
    }    
  }    
 if(phone.length>5){    
    p11=phone.substring(d1+1,d2);    
    if(p11.length>3){    
        p12=p11;    
        l12=p12.length;    
        l15=phone.length;    
        p13=p11.substring(0,3);    
        p14=p11.substring(3,l12);    
        p15=phone.substring(d2+1,l15);    
        txt.value="";    
        pp="("+p13+")"+p14+p15;    
        txt.value=pp;    
    }    
    l16=phone.length;    
    p16=phone.substring(d2+1,l16);    
    l17=p16.length;    
    if(l17>3&&p16.indexOf('-')==-1){    
        p17=phone.substring(d2+1,d2+4);    
        p18=phone.substring(d2+4,l16);    
        p19=phone.substring(0,d2+1);    
        pp=p19+p17+"-"+p18;    
        txt.value=pp;    
    }    
 }    
}    
    </script> </head>   
<body>    
    <form id="form1" runat="server">    
        <asp:TextBox ID="TextBox1" runat="server" onkeyup='ValidatePhone(this)'></asp:TextBox>    
    </form>    
</body>    
</html>

 

Phone number (123) 456-7890

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="TEST.aspx.vb" Inherits="TEST" %>   
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">    
<html xmlns="http://www.w3.org/1999/xhtml">    
<head runat="server">    
    <title>Untitled Page</title>    
   <script language="javascript" type="text/javascript"> 
function ValidatePhone(txt){   
var d4;    
var d5;    
var d1;    
var d2;    
var pp;    
 var phone=txt.value;    
 if(phone.length==3){    
     pp=phone;    
     d4=phone.indexOf("(");    
     d5=phone.indexOf(")");    
    if(d4==-1){    pp="("+pp;    }    
    if(d5==-1){    pp=pp+") ";    }    
    txt.value=pp;    
    }    
 if(phone.length>3){    
     d1=phone.indexOf("(");    
     d2=phone.indexOf(")");    
    if (d2==-1){    
        l30=phone.length;    
        p30=phone.substring(0,4);    
        p30=p30+") ";    
        p31=phone.substring(4,l30);    
        pp=p30+p31;    
        txt.value=pp;    
    }    
  }    
 if(phone.length>5){    
    p11=phone.substring(d1+1,d2);    
    if(p11.length>3){    
        p12=p11;    
        l12=p12.length;    
        l15=phone.length;    
        p13=p11.substring(0,3);    
        p14=p11.substring(3,l12);    
        p15=phone.substring(d2+1,l15);    
        txt.value="";    
        pp="("+p13+") "+p14+p15;    
        txt.value=pp;    
    }    
    l16=phone.length;    
    p16=phone.substring(d2+2,l16);    
    l17=p16.length;    
    if(l17>3&&p16.indexOf("-")==-1){    
        p17=phone.substring(d2+2,d2+5);    
        p18=phone.substring(d2+5,l16);    
        p19=phone.substring(0,d2+2);    
        pp=p19+p17+"-"+p18;    
        txt.value=pp;    
    }    
 }    
}    
    </script></head>   
<body>    
    <form id="form1" runat="server">    
        <asp:TextBox ID="TextBox1" runat="server" onkeyup='ValidatePhone(this)'></asp:TextBox>    
    </form>    
</body>    
</html>



标签:pp,Phone,Auto,number,substring,phone,length,txt,d2
From: https://blog.51cto.com/emanlee/8276039

相关文章

  • 10 Mar 10 Auto Complete Ajax Scripts
    In2005whenGoogleimplementedGoogleSuggest,Ajaxtookoff.EverywebdeveloperwastryingtoduplicatewhatGoogleaccomplished.Itsnow2008andtherearetonsofwaystoaccomplishGoogleSuggest.Belowisalistof10AutoCompleteScriptswithvar......
  • Required request parameter 'numbers' for method parameter type String[] is not p
    报错就是这个,然后报错的信息再给点详细的 org.springframework.web.bind.MissingServletRequestParameterException:Requiredrequestparameter'numbers'formethodparametertypeString[]isnotpresent atorg.springframework.web.method.annotation.RequestParam......
  • ECMAScript中有5种原始类型,即undefined、null、number、string、boolean。
    ECMAScript中,变量可以存放两种类型的值,即原始值和引用值。原始值是存储在栈中的简单数据段,也就是说,它们的值直接存储在变量访问的位置。引用值是存储在堆中的对象,也就是说,存储在变量处的值是一个指针,指向存储对象的内存处。ECMAScript中有5种原始类型,即undefined、null、number......
  • octal number system
    #define_CRT_SECURE_NO_WARNINGS#include<stdio.h>intbin(intn){ if(n<8) returnn; else returnbin(n/8)*10+n%8;}intmain(){ inti,t; scanf("%d",&t); for(i=1;i<=t;i++) { inta; scanf("%d......
  • JSTL fmtformatNumber日期、 数字、货币格式化
    JSTLfmt:formatNumber日期、数字、货币格式化使用<fmt>标签应先导入<%@taglibprefix="fmt"uri="http://java.sun.com/jsp/jstl/fmt"%>其uri可在fmt.tld文件下 1、日期格式化<fmt:formatDatevalue=“${XXX.date}”pattern=“yyyy-MM-ddHH:mm:ss”/> value:要......
  • 游戏评测CQ9玩家困扰:iOS 17 Bug困扰苹果,iPhone 16项目调整中
    苹果近日面临着iOS更新率的放缓问题,引发了一些不满,而苹果也对此表示了关切。最新CQ9游戏评测报道指出,苹果内部已通知员工,为了应对早期版本出现大量bug的问题,他们将推迟明年的iPhone、iPad和Mac软件更新。此次的重点任务不再是新增功能,而是修复缺陷并提高软件性能。据悉,苹果的软件工......
  • [论文阅读] EMO@ Earth Mover Distance Optimization for Auto-Regressive Language M
    Pretitle:EMO:EarthMoverDistanceOptimizationforAuto-RegressiveLanguageModelingaccepted:arXiv2023paper:https://arxiv.org/abs/2310.04691code:https://github.com/DRSY/EMOref:https://spaces.ac.cn/archives/9797关键词:language-modeling,optimalt......
  • mysql中的并列/非并列排名:rank() over() 、dense_rank() over()以及 row_number() ove
    前言:使用sql查询数据的时候,我们有时候需要根据具体的字段值进行排名,下面使用几个栗子来说明rank在sql中的作用下面用到的表名:user_visit_stats主要字段包括:用户id(uid),部门名称(dept_name),访问次数(visit_count)1、格式:rank() over(orderby[列名])根据访问量降序排名,访问......
  • DataGridView的AutoGenerateColumns控制显示列
    在用C#的EF框架进行数据显示的时候出现了DataGridView显示未编辑列的问题,后来发现通过对DataGridView的 AutoGenerateColumns属性进行定义借可以解决AutoGenerateColumns属性默认未true,此时会显示所有,更改为false就可以了(此属性只能后台操控,代码加载main方法里)this.UsersDGV.......
  • sql server 排序 row_number() over(order by ) as row /
    第一种排序方法:利用row_number()over(orderbycreatetimedesc)asrow参考来源:版权声明:本文为CSDN博主「云游的二狗」的原创文章,遵循CC4.0BY-SA版权协议,转载请附上原文出处链接及本声明。原文链接:https://blog.csdn.net/missingshirely/article/details/44037037语法如......