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>