VFP Regular expression to determine whether it is a mobile phone number/e-mail

Source: Internet
Author: User

Regular expressions, which can be understood as character matching or search techniques, are important in the notation of the pattern attribute.

*--determine if it is a mobile phone number
Function Ismobiphone
Lparameters CSTR
Oregexp=newobject ("Qyregexp", "PRG\QYREGEXP.PRG")
Oregexp.pattern= "1\d{10}" && represents 1, matched 10 digits are numbers
Oregexp.ignorecase=. T.
Return Oregexp.test (CStr)
Endproc
*--to determine if it is an e-mail address
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

Whether the *--global property finds the full string ignorecase property ignores case
The *--pattern property sets or returns a regular expression for searching on the Web site
The *--test method performs a regular expression search on a string and returns a Boolean value that indicates whether the match succeeded
*--replace This method is used to replace the text found in the regular expression search
*--execute This method applies a regular expression to a string and returns the matches array in the current class
Define Class Qyregexp as Custom
pattern= "*"
Dimension Matches (a)
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 is not zero-based
This.matches[i, 2] = Lomatch.value
i = i + 1
ENDfor
Lomatches =. F.
Loregex =. F.
Return i-1
Enddefine
Expand Ask Read here
Http://www.baidu.com/link?url=VT-ZYtKQjECWcCwBZ_4UKKXLyq_B5JNbYIGHla-HyvXEco4VPmXISGUVOlge_ZXS_PC3EtdWgFDLb5-AlTzXBa

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.