〖原创〗如何在powerbuilder验证E-mail地址的合法有效性?

1、object

window:w_frame

SingleLineEdit control:sle_mail

2、event

modified

3、powerscript

BOOLEAN  lb_part1_valid,lb_part2_valid,lb_part3_valid
STRING   ls_matchstring
STRING   ls_part1,ls_part2,ls_part3
INTEGER  li_posa,li_posdot
INTEGER  li_postemp1,li_postemp2
STRING   ls_tempstring

ls_matchstring = Trim(THIS.Text)
IF IsNull(ls_matchstring) OR ls_matchstring = "" THEN RETURN

//"@"pos
li_posa = Pos(ls_matchstring,"@")
//last's"."pos,仅高版本pb提供
li_posdot= LastPos(ls_matchstring,".")
//截取到part1
ls_part1 = Left(ls_matchstring,li_posa)
//截取到part2
ls_part2 = "." + Mid(ls_matchstring,li_posa + 1,li_posdot - li_posa)
//截取到part3
ls_part3 = Mid(ls_matchstring,li_posdot+ 1)

//检测 part1's 有效性,规格<hygougou@|hy-gougou@|hy_gougou@|hy.gougou@>
lb_part1_valid = Match(ls_part1,"^[A-Za-z0-9_/-/.]+@")

//检测 part2's 有效性,规格<hotmail.|vip.163.|sl-mail>
li_postemp1 = Pos(ls_part2,".")
li_postemp2 = Pos(ls_part2,".",li_postemp1 + 1)
DO WHILE li_postemp2 > 0
 ls_tempstring = Mid(ls_part2,li_postemp1 + 1,li_postemp2 - li_postemp1)
 lb_part2_valid = Match(ls_tempstring,"^[A-Za-z0-9/-]+/.")
 IF NOT lb_part2_valid THEN Exit
 li_postemp1 = li_postemp2
 li_postemp2 = Pos(ls_part2,".",li_postemp1 + 1)
LOOP

//检测 part3's 有效性,后缀>1,<5,规格<cn|com|slof>
lb_part3_valid = Match(ls_part3,"^[A-Za-z0-9][A-Za-z0-9][A-Za-z0-9]?[A-Za-z0-9]?$")


IF NOT lb_part1_valid  OR NOT lb_part2_valid OR NOT lb_part3_valid THEN
 Messagebox("提示","输入的E-Mail地址有误,请重新输入!")
 THIS.SetFocus()
 THIS.SelectText(1,Len(THIS.Text))
END IF

阅读更多

没有更多推荐了,返回首页