Paradox Community

Items in pnews.paradox-programming

Subject:Re: isEmailAddress()
Date:10 Oct 2019 10:25:36 -0400
From:"Thies Grimm" <thies.grimm@t-online.de>
Newsgroups:pnews.paradox-programming

Hi Everyone,

I tried a little powershell script:

======================================================
method cmisValidEmailaddress(
				stEmailAddress string,
				var lgRes Logical
				)Logical
var
	ts						TextStream
	stVar					String
endVar

; //	write PowerShell-Script

	ts.open(":priv:__cmCheckEmail.ps1", "nw")

	ts.writeLine("$EmailAddress=\"" + lTrim(rTrim(stEmailAddress)) + "\"")
	ts.writeLine("$IsValidEmailAddress='True'")
	ts.writeLine(" Try ")
	ts.writeLine(" { ")
	ts.writeLine("	  New-Object System.Net.Mail.MailAddress($EmailAddress) ")
	ts.writeLine(" } ")
	ts.writeLine(" Catch ")
	ts.writeLine(" { ")
	ts.writeLine("	 $IsValidEmailAddress='False'")
	ts.writeLine(" } ")
	ts.writeLine("$IsValidEmailAddress | set-content " + privDir() + "\\__result.txt")

	ts.close()

; //	execute PowerShell-Script
	if not execute("Powershell -file " + privDir() + "\\__cmCheckEmail.ps1",
True, exehidden) then
		errorshow()
		return False
	endIf	

; //	read result from file
	if not ts.open(":priv:__result.txt", "r") then
		errorshow()
		return False
	endif
	ts.readLine(stVar)
	ts.close()

; //	Result
	switch
		case stVar = "True":  lgRes = True	
									 return True
		case stVar = "False": lgRes = True
									 errorLog(UserError, "no valid EmailAddress: \n" + stEmailAddress)
									 return False
		otherWise:				 return False
	endSwitch
	
endMethod
======================================================

calling it like this:

======================================================
method run(var eventInfo Event)
var
	lgRes					Logical
endVar

	if not cmisValidEmailaddress("max.mustermann@t-online.de", lgRes) then
		msgStop("isValidEmailaddress", errorMessage())
		return
	endIf

	msginfo("Result", string(lgRes)) 

endMethod
======================================================

what do you think about it? Does it work at your place?

Thies

Kevin Baker <shcsbaker@gmail.com> wrote:
>Hi Everyone,
>
>Was looking into the undocumented methods this weekend and came across 
>isEmailAddress.  I did a search on the forms and didn't find any post on

>this method.  I created a single button form to test this method and it

>works.  Does anyone have any experience is using this?  Think it's okay

>to use in production code?
>
>
>Here's the code on the button:
>
>var
>    em string
>endvar
>
>em = "shcsbaker@gmail.com"
>
>if isEmailAddress(em) then
>    msginfo("Message","Is valid.")
>else
>    msginfo("Message","Not valid.")
>endif
>
>Thanks
>Kevin


Copyright © 2004 thedbcommunity.com