VFPRegex判斷是否是手機號碼/電子郵件

來源:互聯網
上載者:User

標籤:http   for   io   cti   re   c   

Regex,可以理解為字元匹配或搜尋技術 ,重要的是Pattern屬性的寫法.

*--判斷是否是手機號碼
Function isMobiPhone
Lparameters cStr
oRegExp=Newobject("QYRegexp","Prg\qyregexp.prg")
oRegExp.Pattern="1\d{10}" &&表示1開頭,匹配10位都是數字
oRegExp.IgnoreCase=.T.
Return oRegExp.test(cstr)
Endproc
*--判斷是否是郵件地址
Function isEmailAddr(tcEmai)
Local oRegExp
oRegExp=CREATEOBJECT("QyRegExp")
oRegExp.Pattern = "^(([A-Za-z0-9]+_+)|" ;
+ "([A-Za-z0-9]+\-+)|" ;
+ "([A-Za-z0-9]+\.+)|" ;
+ "([A-Za-z0-9]+\++))*" ;
+ "[A-Za-z0-9][email protected]((\w+\-+)|" ;
+ "(\w+\.))*\w{1,63}\.[a-zA-Z]{2,6}$"
Return oRegExp.test(tcEmai)
Endfunc

*--Global屬性 是否尋找全字串 IgnoreCase屬性 是否忽略大小寫
*--Pattern屬性設定或返回用於搜尋的Regex 見網站上
*--Test方法對字串執行Regex搜尋,並返回一個布爾值說明匹配是否成功
*--Replace 這個方法用於替換在Regex搜尋中找到的文本
*--Execute 這個方法將Regex應用到字串上 並返回當前類中Matches數組
Define Class QyRegExp As Custom
Pattern="*"
Dimension matches(1,1)
matches=.F.
Global=.T.
IgnoreCase=.F.
oRegExp=.F.

Procedure Clear
This.Pattern = "*"
This.matches = .F.
Endproc

Procedure test
Lparameters cStr
Local loRegExp
loRegExp=Createobject("VBScript.RegExp")
loRegExp.Global=This.Global
loRegExp.Ignorecase=This.Ignorecase
loRegExp.Pattern=This.Pattern
Return loRegExp.Test(cStr)
Endproc

Procedure Replace
Lparameters cStr,cReplacestr
Local loRegExp
loRegExp=Createobject("VBScript.RegExp")
loRegExp.Global=This.Global
loRegExp.Ignorecase=This.Ignorecase
loRegExp.Pattern=This.Pattern
Return loRegExp.Replace(cStr,cReplacestr)
Endproc

Procedure Execute
Lparameters tcStr
Local loMatch, loMatches, i
Local loRegExp
loRegExp=Createobject("VBScript.RegExp")
loRegExp.Global=This.Global
loRegExp.Ignorecase=This.Ignorecase
loRegExp.Pattern=This.Pattern

loMatches = loRegExp.execute(tcStr)
Dimension This.matches[Max(loMatches.count,1),2]
taMatchInfo = .F.
i = 1
For Each loMatch In loMatches
This.matches[i, 1] = loMatch.firstIndex + 1 && fox strings are not zero-based
This.matches[i, 2] = loMatch.Value
i = i + 1
Endfor
loMatches = .F.
loRegEx = .F.
Return i -1
Enddefine
擴充問讀看這裡
http://www.baidu.com/link?url=VT-ZYtKQjECWcCwBZ_4UKKXLyq_B5JNbYIGHla-HyvXEco4VPmXISGUVOlge_ZXS_PC3EtdWgFDLb5-AlTzXBa

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.