![]() |
#2
schtg昨天 06:29
|
已经放入表单测试过,好像没有问题。
代码如下:

**************************************************
*-- 类: txt_phone (d:\documents\visual foxpro 项目\myclass.vcx)
*-- 父类: textbox
*-- 基类: textbox
*-- 时间戳: 10/08/25 09:40:09 PM
*
DEFINE CLASS txt_phone AS textbox
Value = (space(14))
Height = 20
Width = 100
*-- 分隔符
decollater = "-"
Name = "txt_phone"
PROCEDURE InteractiveChange
DO CASE
CASE LEN(ALLTRIM(this.value))=3
IF INLIST(SUBSTR(this.Value,1,1),"0","1")
IF SUBSTR(this.Value,1,2)="01" OR SUBSTR(this.Value,1,2)="02" OR SUBSTR(this.Value,1,1)="1"
*!* 座机区号01或02开头,手机则以1开头
this.Value=ALLTRIM(this.Value)+SPACE(1)+this.decollater
this.SelStart=LEN(this.Value)
this.SelLength=4
ENDIF
ELSE
SET MESSAGE TO "电话号码的首尾应为0或1"
this.SelStart=0
this.SelLength=3
ENDIF
CASE LEN(allt(this.value))=9
this.Value=ALLTRIM(this.Value)+this.decollater
this.SelStart=LEN(this.Value)
this.sellength=4
CASE LEN(ALLTRIM(this.value))=4
this.Value=ALLTRIM(this.Value)+this.decollater
this.SelStart=LEN(this.Value)
this.SelLength=4
ENDCASE
ENDPROC
PROCEDURE KeyPress
LPARAMETERS nKeyCode, nShiftAltCtrl
IF !(BETWEEN(nkeycode,48,57) OR INLIST(nkeycode,32,9,19,4,13,127,7))
*!* 只允许输入0-9,空格,tab,左箭头,右箭头,回车,退格,删除
NODEFAULT
ENDIF
*!* 假设text的值为0571-8888-9999
*!* 座机号
*!* 基础结构:由区号(3-4位 如:021,0571)和本地号码8位(还有少部分地区7位)组成,总位长不超过11位
*!* 手机号
*!* 前3位:网络识别号(区分运营商,如移动134-139、联通130-132、电信133等)
*!* 4-7位:地区编码(标识归属地)
*!* 8-11位:用户号码(随机分配)
*!* 1,当前控件区号段只允许输入0-9数字,以及空格
*!* 第一位,只能是0(座机),或1(手机);
*!* 三位区号城市列表
*!* 北京 - 010(首都,全国政治文化中心)
*!* 广州 - 020(华南地区核心城市)
*!* 上海 - 021(全国经济中心)
*!* 天津 - 022(北方重要港口城市)
*!* 重庆 - 023(西部直辖市)
*!* 沈阳 - 024(东北地区中心城市)
*!* 南京 - 025(华东地区重要城市)
*!* 台北 - 026 (预留)
*!* 武汉 - 027(中部交通枢纽)
*!* 成都 - 028(西南地区核心城市)
*!* 西安 - 029(西北地区中心城市)
ENDPROC
PROCEDURE Valid
n=ALINES(atemp,this.Value,5,this.decollater)
IF LEN(ALLTRIM(this.value))<13 &&不完整
this.SelStart=0
this.SelLength=3
RETURN .f.
ENDIF
*****************************************************************
*这段代码有点多余,好像不会发生了,interactivechange里已经避免了*
IF !INLIST(SUBSTR(this.Value,1,1),"0","1")
this.SelStart=0
this.SelLength=IIF(AT(this.decollater,this.Value)=0,4,AT(this.decollater,this.Value))-1
ENDIF
*****************************************************************
n=ALINES(atemp,this.Value,5,this.decollater )
IF n<3
this.SelStart=0
this.SelLength=AT(this.decollater ,this.Value)-1
RETURN .f.
ELSE
DO CASE
CASE LEN(ALLTRIM(atemp(1)))<3 OR LEN(ALLTRIM(atemp(1)))>4
this.SelStart=0
this.SelLength=LEN(ALLTRIM(atemp(1)))
RETURN .f.
CASE LEN(ALLTRIM(atemp(2)))<4
this.SelStart=5
this.SelLength=4
RETURN .f.
CASE LEN(ALLTRIM(atemp(3)))<3
this.SelStart=9
this.SelLength=4
RETURN .f.
ENDCASE
ENDIF
ENDPROC
ENDDEFINE
*
*-- EndDefine: txt_phone
**************************************************