Write a script that inputs a telephone number as a string in the form (555) 555-5555. the script should use string method split to extract the area code as a token, the first three digits of the phone number as a token and the last four digits of the phone number as a token.
Answers
Answered by
3
script that inputs a telephone number as a string in the form (555) 555-5555. the script should use string method split to extract the area code as a token, the first three digits of the phone number as a token and the last four digits of the phone number as a token.is given below
........
_________. by the HTML ________
<html>
<head>
<script type="text/javascript">
function compute()
{
var a=document.desg.telno.value;
if(a.length<10)
{
------------ alert("Enter the phone no");
return false;
}
return true;
}
</script>
</head>
<form name="desg" action="chk.jsp">
<body>
Enter the telephone Number<input type="text" name="telno">
<input type="submit" value="Calculate"
onClick="return compute()">
</body>
</form>
</html>
_____________.
<html>
<body>
<%String tn=request.getParameter("telno");
String acode=tn.substring(0,3);
String f4=tn.substring(3,7);
String l3=tn.substring(7,10);
%>
Areacode<input type="text" name="ac" value=<%=acode%>><br>
first 3digit phone no <input type="text"
name="f3" value=<%=f4%>><br>
Last 4digit phone no <input type="text"
name="l4" value=<%=l3%>>
</body>
</html>
........
_________. by the HTML ________
<html>
<head>
<script type="text/javascript">
function compute()
{
var a=document.desg.telno.value;
if(a.length<10)
{
------------ alert("Enter the phone no");
return false;
}
return true;
}
</script>
</head>
<form name="desg" action="chk.jsp">
<body>
Enter the telephone Number<input type="text" name="telno">
<input type="submit" value="Calculate"
onClick="return compute()">
</body>
</form>
</html>
_____________.
<html>
<body>
<%String tn=request.getParameter("telno");
String acode=tn.substring(0,3);
String f4=tn.substring(3,7);
String l3=tn.substring(7,10);
%>
Areacode<input type="text" name="ac" value=<%=acode%>><br>
first 3digit phone no <input type="text"
name="f3" value=<%=f4%>><br>
Last 4digit phone no <input type="text"
name="l4" value=<%=l3%>>
</body>
</html>
Answered by
0
Answer:
StringBuilder phoneNumber=new StringBuilder("5555555555");
phoneNumber.insert(3, " ");
phoneNumber.insert(7, " ");
String [] phone=phoneNumber.toString().split(" ");
System.out.println("(".concat(phone[0]).concat(")").concat(phone[1])+"-"+phone[2]);
Explanation:
we use String method split to make a 3 tokens and store 3 tokens into array phone then we attached () and - betwwen numbers
Similar questions