用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
' 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> 

时间: 2024-10-31 22:35:41

用ASP实现号码转换的相关文章

asp数据强制转换的方法

asp数据强制转换  CBool(expression) CByte(expression) CCur(expression) CDate(expression) CDbl(expression) (保留小数) CDec(expression) CInt(expression) (不保留小数) CLng(expression) (不保留小数) CSng(expression) CStr(expression) CVar(expression) CStr(expression) Vbscript类

ASP处理XSLT转换XML的实现

使用ASP处理XSLT转换XML比较简单,思路如下:创建一个XSLTemplate的对象,再创建一个XMLDOM对象,然后在家Xml文件和XSLT文件,最后使用方法transform即可,包含到类里面,具体代码如下: 以下是引用片段: Class Cls_Xml_Transform Private lInput,XSLTemplate Private p_Output Public Property Get Output() Output = p_Output End Property Priv

MaxCompute UDF系列之身份证校验及15位身份证号码转换成18位

为了验证一些老证件上的身份证号码到底是不是本人,今天为大家提供一个15位身份证号码转换成18位的MaxCompute的UDF,下载地址见附件. 效果如下: MaxCompute UDF代码如下: /*** * 身份证号码构成:6位地址编码+8位生日+3位顺序码+1位校验码 * 验证15位,18位证件号码是否有效:15位号码将直接转为18位: * 校验身份证号码除了校验位是否为数值,校验省份.出生日期 * 校验位不正确的会被正确的替代 * 出生日期逻辑有效性,即是否1900年前出生,是否当前日期后

asp相对路径转换成绝对路径

asp相对路径转换成绝对路径 Public Function ChkMapPath(ByVal strPath)  On Error Resume Next  Dim fullPath  strPath = Replace(Replace(Trim(strPath), "//", "/"), "\\", "\")  If strPath = "" Then strPath = "."  

asp的日期转换星座函数

经过长时间学习ASP.NETWeb,于是和大家分享一下,看完本文你肯定有不少收获,希望本文能教会你更多东西.学习ASP.NETWeb时,你可能会遇到相关问题,这里将介绍ASP.NETWeb问题的解决方法. 该结构分三个层次:表示层.业务层.数据层.数据层:代表物理数据库.业务层:负责数据层与表示层之间的数据传输.表示层:应用程序的客户端,它通过业务层来访问数据库. 表示层所操作的是驻留在内存中的本地数据,当需要更新数据库数据时,要通过业务层提供的更新方法实现.这样可以大大提高应用程序的性能,而且

将ASP动态网页转换成HTM静态页面的方法

动态|静态|网页|页面|转换 前段时间有个asp页面执行起来很慢,访问人数又颇多,而且又不经常修改,又懒得直接做成静态的,每次都要从服务器下载来改,只好想办法把asp页面转化成htm静态页面了. 以前就曾经看到这样的文章,不过没太在意,真正想用的时候很难找到一个合适的,于是在网上搜索了半天终于找到比较合适的代码再加上自己的修改,如下: <%Function GetPage(url)  '获得文件内容 dim Retrieval Set Retrieval = CreateObject("M

身份证号码转换-JAVA

问题描述 publicStringupTo18(StringidCard)throwsException{idCard=IdCard15to18(idCard);Strings=idCard.replaceAll("\d","").trim();if(s!=null&&!"".equals(s)){charc=s.charAt(0);if(c>='a'&&c<='z'){c=(char)(c-('a'-

asp.net 汉字转换拼音及首字母实现代码_实用技巧

Default.aspx页面 复制代码 代码如下: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:

ASP字符串大写转换成小写 ASP小写转换成大写 ucase lcase_ASP基础

LCase:转成小写 UCase:转成大写 下面是ASP中的代码,可以直接演示效果的. 复制代码 代码如下: <% dim str,str1,str2 str="AbCdEf" str1=LCase(str) str2=UCase(str) Response.write("LCase转换小写"&str1 & ",UCase转换大写" & str2) %> 而.NET中将字符串转换为大写ToUpper(),将字符