网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > ASP技巧
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
本月文章推荐
.一种比较方便的ASP分页程序.
.ASP服务器组件编程心得.
.用ASP控制Flash.
.关于Cookie跨域操作遇到的问题及.
.ASP提速技巧.
.PHP和C通过Socket通信--UDP篇.
.ASP程序中使用断开的数据记录集.
.小工具:统计有多少行JS代码和AS.
.构建你的网站新闻自动发布系统之.
.存储过程分页.
.无组件生成BMP验证码.
.用ASP和WML来实现数据库查询.
.学习ASP有用的代码(很有用哦!).
.WEB打印设置解决方案四(在ASP中.
.用asp获取文件md5值.
.两个不同数据库表的分页显示解决.
.Server Application Error详细解.
.加密处理使密码更安全[CFS编码加.
.ASP技术在论坛中的运用(三)(吐血.
.解决ASP执行DB查询中的特殊字符问.

用ASP实现号码转换

发表日期:1999-5-6


<%
'***** BEGIN FUNCTION AREA *****

' Formats a given 10 digit number into a nice looking phone number
' Example: given strNumber of 8005551212 you get (800) 555-1212
Function FormatPhoneNumber(strNumber)
Dim strInput ' String to hold our entered number
Dim strTemp ' Temporary string to hold our working text
Dim strCurrentChar ' Var for storing each character for eval.
Dim I ' Looping var

' Uppercase all characters for consistency
strInput = UCase(strNumber)

' To be able to handle some pretty bad formatting we strip out
' all characters except for chars A to Z and digits 0 to 9
' before proceeding. I left in the chars for stupid slogan
' numbers like 1-800-GET-CASH etc...
For I = 1 To Len(strInput)
strCurrentChar = Mid(strInput, I, 1)
' Numbers (0 to 9)
If Asc("0") <= Asc(strCurrentChar) And Asc(strCurrentChar) <= Asc("9") Then
strTemp = strTemp & strCurrentChar
End If
' Upper Case Chars (A to Z)
If Asc("A") <= Asc(strCurrentChar) And Asc(strCurrentChar) <= Asc("Z") Then
strTemp = strTemp & strCurrentChar
End If
Next 'I

' Swap strTemp back to strInput for next set of validation
' I also clear strTemp just for good measure!
strInput = strTemp
strTemp = ""

' Remove leading 1 if applicable
If Len(strInput) = 11 And Left(strInput, 1) = "1" Then
strInput = Right(strInput, 10)
End If

' Error catch to make sure strInput is proper length now that
' we've finished manipulating it.
If Not Len(strInput) = 10 Then
' Handle errors as you see fit. This script raises a real
' error so you can handle it like any other runtime error,
' but you could also pass an error back via the function's
' return value or just display a message... your choice!
Err.Raise 1, "FormatPhoneNumber function", _
"The phone number to be formatted must be a valid 10 digit US phone number!"

' Two alternative error techniques!
'Response.Write "<B>The phone number to be formatted must be a valid phone number!</B>"
'Response.End

' Note if you use this you'll also need to check for
' this below so you don't overwrite it!
'strTemp = "<B>The phone number to be formatted must be a valid phone number!</B>"
End If

' If an error occurred then the rest of this won't get processed!

' Build the output string formatted to our liking!
' (xxx) xxx-xxxx
strTemp = "(" ' "("
strTemp = strTemp & Left(strInput, 3) ' Area code
strTemp = strTemp & ") " ' ") "
strTemp = strTemp & Mid(strInput, 4, 3) ' Exchange
strTemp = strTemp & "-" ' "-"
strTemp = strTemp & Right(strInput, 4) ' 4 digit part

' Set return value
FormatPhoneNumber = strTemp
End Function

'***** END FUNCTION AREA *****
%>


<%' Runtime Code
Dim strNumberToFormat ' The phone number we pass to the function


' Retrieve the requested number or set it to the default
If Request.QueryString("phone_number") <> "" Then
strNumberToFormat = Request.QueryString("phone_number")
Else
strNumberToFormat = "1-800-555-1212"
End If

' We need to turn this on if we want to trap errors.
' Otherwise the script would generate an error if the input
' number wasn't correct.
On Error Resume Next
%>

<TABLE BORDER="1">
<TR>
<TD>Phone number before formatting:</TD>
<TD><%= strNumberToFormat %></TD>
</TR>
<TR>
<TD>Phone number after formatting:</TD>
<TD>
<%
' Call the function and output the results
Response.Write FormatPhoneNumber(strNumberToFormat)

' Check for an error and display the message if one occurred
If Err.number Then Response.Write Err.description
%>
</TD>
</TR>
</TABLE>

<FORM ACTION="39.asp" METHOD="get">
Phone number to format: <INPUT TYPE="text" NAME="phone_number" VALUE="<%= strNumberToFormat %>">
<INPUT type="submit" value="Submit">
</FORM> 
上一篇:用ASP进行网络打印功能 人气:10543
下一篇:如何用ASP创建日志文件 人气:13289
浏览全部号码转换的内容 Dreamweaver插件下载 网页广告代码 祝你圣诞节快乐 2009年新年快乐