Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding specific characters in strings 3

Status
Not open for further replies.

bosox

IS-IT--Management
Jan 4, 2002
2
US
I'm using VFP 7.0 and have an email field in one of my tables. I need to find all the records where there is an illegal email address (i.e. no '@' character). Can anyone tell me how to select those records where field(email) doesn't contain a '@')?

Thanks for your help!
 
if AT("@",cField) = 0
? "@ was not found"
else
? "@ was Found"
endif


Ali Koumaiha
Wireless Toyz
Farmington Hills, Michigan
 
in a Select Statement:

Sele * from YourTable where At('@',YourField) > 0 Order by YourOrder Into Cursor SomeCursor

Ali Koumaiha
Wireless Toyz
Farmington Hills, Michigan
 
Wow, you guys are too much! The solution to my question came within 6 minutes of my posting! Thank you!!!!!
 
You are welcome bosox.

Ali Koumaiha
Wireless Toyz
Farmington Hills, Michigan
 
bosox,

Not quite sure what you are using for your functionality, but here's something I worked up...

Code:
?IsEmailValid("craig1442@.com")
?IsEmailValid("craig1442@mchsi.com")

FUNCTION IsEmailValid(tcEmailAddy)
LOCAL lnAtSymbol, lnDotSymbol, lnLength, lnAtOccurs, llInvalid, lnDomainLen, lnTogether 

tcEmailAddy = ALLTRIM(tcEmailAddy) && optional if you want

lnAtSymbol = AT("@",tcEmailAddy)
lnDotSymbol = AT(".",tcEmailAddy)
lnLength = LEN(tcEmailAddy)
lnAtOccurs = OCCURS("@", tcEmailAddy)
llInvalid = LEN(CHRTRAN(tcEmailAddy, "!#$%^&*()=+{}[]|\;:'/?>,< ","")) != lnLength
lnDomainLen = RAT(".", tcEmailAddy)
lnTogether = AT("@.", tcEmailAddy) + AT(".@", tcEmailAddy)

DO case
*!* @ cannot be at beginning or end and must occur only once
CASE lnAtSymbol = 1 OR lnAtSymbol = lnLength OR lnAtOccurs != 1
	RETURN .F.

*!* Dot must not be at beginning or end and must occur at least once
CASE lnDotSymbol < 2 OR lnDotSymbol = lnLength
	RETURN .F.

*!* length must be at least 8 (xx@xx.xx)
CASE lnLength < 8
	RETURN .F.

*!* @ and Dot cannot be together
CASE lnTogether > 0
	RETURN .F.

*!* subdomain must be at least 2 characters long (additional check could be done on all valid subdomains)
CASE lnDomainLen < 2
	RETURN .F.

*!* no invalid characters
CASE llInvalid
	RETURN .F.
	
*!* Email is potentially valid
OTHERWISE
	RETURN .T.
ENDCASE

...this could obviously be added to greatly but it does provide some measure of protection against invalid email entries. Also, just a little post note, this thread would have probably been better posted in the following forum given that it deals with email:

Microsoft: VFP - Automation, Mail & 3rd Party Svcs Forum
forum1251

boyd.gif

[sub]craig1442@mchsi.com[/sub][sup]
&quot;Whom computers would destroy, they must first drive mad.&quot; - Anon​
[/sup]
 
Good code Craig. *thumbsup*

Ali Koumaiha
Wireless Toyz
Farmington Hills, Michigan
 
Thanks for the star TeknoSDS. [smile]

boyd.gif

[sub]craig1442@mchsi.com[/sub][sup]
&quot;Whom computers would destroy, they must first drive mad.&quot; - Anon​
[/sup]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top