|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
缺乏可以共同遵循的行业标准,ASP还处在发展初期,大家对它的理解不同,如产品和服务标准,收费标准等,不利于行业的健康发展。<%
*****BEGINFUNCTIONAREA*****
Formatsagiven10digitnumberintoanicelookingphonenumber
Example:givenstrNumberof8005551212youget(800)555-1212
FunctionFormatPhoneNumber(strNumber)
DimstrInputStringtoholdourenterednumber
DimstrTempTemporarystringtoholdourworkingtext
DimstrCurrentCharVarforstoringeachcharacterforeval.
DimILoopingvar
Uppercaseallcharactersforconsistency
strInput=UCase(strNumber)
Tobeabletohandlesomeprettybadformattingwestripout
allcharactersexceptforcharsAtoZanddigits0to9
beforeproceeding.Ileftinthecharsforstupidslogan
numberslike1-800-GET-CASHetc...
ForI=1ToLen(strInput)
strCurrentChar=Mid(strInput,I,1)
Numbers(0to9)
IfAsc("0")<=Asc(strCurrentChar)AndAsc(strCurrentChar)<=Asc("9")Then
strTemp=strTemp&strCurrentChar
EndIf
UpperCaseChars(AtoZ)
IfAsc("A")<=Asc(strCurrentChar)AndAsc(strCurrentChar)<=Asc("Z")Then
strTemp=strTemp&strCurrentChar
EndIf
NextI
SwapstrTempbacktostrInputfornextsetofvalidation
IalsoclearstrTempjustforgoodmeasure!
strInput=strTemp
strTemp=""
Removeleading1ifapplicable
IfLen(strInput)=11AndLeft(strInput,1)="1"Then
strInput=Right(strInput,10)
EndIf
ErrorcatchtomakesurestrInputisproperlengthnowthat
wevefinishedmanipulatingit.
IfNotLen(strInput)=10Then
Handleerrorsasyouseefit.Thisscriptraisesareal
errorsoyoucanhandleitlikeanyotherruntimeerror,
butyoucouldalsopassanerrorbackviathefunctions
returnvalueorjustdisplayamessage...yourchoice!
Err.Raise1,"FormatPhoneNumberfunction",_
"Thephonenumbertobeformattedmustbeavalid10digitUSphonenumber!"
Twoalternativeerrortechniques!
Response.Write"<B>Thephonenumbertobeformattedmustbeavalidphonenumber!</B>"
Response.End
Noteifyouusethisyoullalsoneedtocheckfor
thisbelowsoyoudontoverwriteit!
strTemp="<B>Thephonenumbertobeformattedmustbeavalidphonenumber!</B>"
EndIf
Ifanerroroccurredthentherestofthiswontgetprocessed!
Buildtheoutputstringformattedtoourliking!
(xxx)xxx-xxxx
strTemp="(""("
strTemp=strTemp&Left(strInput,3)Areacode
strTemp=strTemp&")"")"
strTemp=strTemp&Mid(strInput,4,3)Exchange
strTemp=strTemp&"-""-"
strTemp=strTemp&Right(strInput,4)4digitpart
Setreturnvalue
FormatPhoneNumber=strTemp
EndFunction
*****ENDFUNCTIONAREA*****
%>
<%RuntimeCode
DimstrNumberToFormatThephonenumberwepasstothefunction
Retrievetherequestednumberorsetittothedefault
IfRequest.QueryString("phone_number")""Then
strNumberToFormat=Request.QueryString("phone_number")
Else
strNumberToFormat="1-800-555-1212"
EndIf
Weneedtoturnthisonifwewanttotraperrors.
Otherwisethescriptwouldgenerateanerroriftheinput
numberwasntcorrect.
OnErrorResumeNext
%>
<TABLEBORDER="1">
<TR>
<TD>Phonenumberbeforeformatting:</TD>
<TD><%=strNumberToFormat%></TD>
</TR>
<TR>
<TD>Phonenumberafterformatting:</TD>
<TD>
<%
Callthefunctionandoutputtheresults
Response.WriteFormatPhoneNumber(strNumberToFormat)
Checkforanerroranddisplaythemessageifoneoccurred
IfErr.numberThenResponse.WriteErr.description
%>
</TD>
</TR>
</TABLE>
<FORMACTION="39.asp"METHOD="get">
Phonenumbertoformat:<INPUTTYPE="text"NAME="phone_number"VALUE="<%=strNumberToFormat%>">
<INPUTtype="submit"value="Submit">
</FORM>ASP最大的缺点在于网络的安全性和可靠性,企业将经营数据放在开放的平台上,最大的担忧就是如何保证这些数据不被其他人破坏。 |
|