上一篇:如何用ASP创建日志文件 >>
用ASP实现号码转换
***** 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
weve 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 functions
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 youll also need to check for
this below so you dont 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 wont 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 wasnt 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进行网络打印功能 >>
相关文章:
- · 好东西,翻页程序,大家可以参考
- · 大部分的ADO的错误码对应的含义
- · Recordset对象方法详解
- · 不用数据源打开数据库(DSNless connection)
- · 处理二进制数据
- · 利 用 ISAPI 实 现 向 数 据 库 中 添 加 记 录 (六)
- · 利 用 ISAPI 实 现 向 数 据 库 中 添 加 记 录 (五)
- · 利 用 ISAPI 实 现 向 数 据 库 中 添 加 记 录 (四)
- · 利 用 ISAPI 实 现 向 数 据 库 中 添 加 记 录 (三)
- · 利 用 ISAPI 实 现 向 数 据 库 中 添 加 记 录 (二)
- · 利 用 ISAPI 实 现 向 数 据 库 中 添 加 记 录 (一)
- · ASP技术在论坛中的运用(八)(吐血推荐!!!!)
- · ASP技术在论坛中的运用(七)(吐血推荐!!!!)
- · ASP技术在论坛中的运用(六)(吐血推荐!!!!)
- · ASP技术在论坛中的运用(五)(吐血推荐!!!!)
- · ASP技术在论坛中的运用(四)(吐血推荐!!!!)
- · ASP技术在论坛中的运用(三)(吐血推荐!!!!)
- · ASP技术在论坛中的运用(二)(吐血推荐!!!!)
- · ASP技术在论坛中的运用(一)(吐血推荐!!!!)
- · 了解MSMQ,控制ASP进程 (二)
- · 了解MSMQ,控制ASP进程 (一)
- · 在ASP应用中如何限制同一表单被多次提交!!!!好东西
- · ASP环境下邮件列表功能的实现 (四)(推荐)
- · ASP环境下邮件列表功能的实现 (三)(推荐)
- · ASP环境下邮件列表功能的实现 (二)(推荐)
- · ASP环境下邮件列表功能的实现 (一)(推荐)
- · ASP3.0给我们带来的新技术之一---Data Shaping技术
- · 使用ASP加密算法加密你的数据(二)
- · 使用ASP加密算法加密你的数据(一)
- · 微软dvwssr.dll后门
- · 通过asp入侵web server,窃取文件毁坏系统
- · 一个BBS的源代码(六)
- · 一个BBS的源代码(五)
- · 一个BBS的源代码(四)
- · 一个BBS的源代码(三)
- · 一个BBS的源代码(二)
- · 一个BBS的源代码(一)
- · 如何实现动态添加Html文档中Form项
