实用函数- 判断输入的是否是电话号码

Source Code
--------------------------------------------------------------------------------

 1   
 2'******************************************************************************   
 3' ********************** DO NOT DELETE ****************************************   
 4'   
 5' COPYRIGHT NOTICE: Copyright 2000 Nicholas P. LaDieu, node i internet consulting   
 6'   
 7' This code is free for non-commercial use. Any commercial usage or   
 8' duplication requires a licensing agreement from the author who may be   
 9' contacted at the following email address: [email protected]   
10'   
11' The author assumes no responsibility for any damage caused by the   
12' proper or inproper use of this code.   
13'   
14' http://www.nodei.com   
15' ********************** DO NOT DELETE ****************************************   
16'******************************************************************************   
17Function IsPhone(X)   
18Dim FieldOk   
19FieldOk=True   
20For i = 1 to len(X)   
21If IsNumeric(mid(X, i, 1))=False AND mid(X,i,1)<>"-" AND mid(X,i,1)<>"(" AND mid   
22(X,i,1)<>")" then   
23FieldOk=False   
24End If   
25Next   
26'''''''''''''''''NOW STRIP OUT CHARS AND SEE IF WE HAVE A VALID NUMBER   
27  
28For I = 1 To Len(X)   
29strCurrentChar = Mid(X, I, 1)   
30' Numbers (0 to 9)   
31If Asc("0") <= Asc(strCurrentChar) And Asc(strCurrentChar) <= Asc("9") Then   
32strTemp = strTemp & strCurrentChar   
33End If   
34' Upper Case Chars (A to Z)   
35If Asc("A") <= Asc(strCurrentChar) And Asc(strCurrentChar) <= Asc("Z") Then   
36strTemp = strTemp & strCurrentChar   
37End If   
38Next 'I   
39X=strTemp   
40  
41  
42if len(X)=10 AND Left(X,1)="1" then   
43FieldOk=False   
44end if   
45  
46if len(X)<10 then   
47FieldOk=False   
48end if   
49  
50if len(X)>11 then   
51FieldOk=False   
52end if   
53  
54IsPhone=FieldOk   
55End Function   
56'''''''''''''''''''''''''''''''''''''''''''''''   
57'''''''''''''''''''''''''''''''''''''''''''''''   
Published At
Categories with Web编程
Tagged with
comments powered by Disqus