Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
If field contains @
Message
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00903039
Message ID:
00903045
Views:
15
This message has been marked as the solution to the initial question of the thread.
Here's a little bit more than you asked for. :) Still it doesn't guaranty that email addres will be valid.
* Function ValidateEmaiAddress
PARAMETERS m.EmailAddr
PRIVATE m.EmailIsOk, m.Allowed, m.EmAddr, m.Domain, m.MailBox  
m.EmAddr = UPPER(ALLTRIM(m.EmailAddr))
m.Domain = SUBSTR(m.EmAddr, AT("@",m.EmAddr)+1)
m.MailBox = LEFT(m.EmAddr, AT("@",m.EmAddr)-1)
m.Allowed = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ-_.@1234567890'
m.EmailIsOk = .T.
DO CASE
CASE LEN( CHRTRAN( UPPER( ALLTRIM(m.EmAddr)), m.allowed, "")) > 0
	* Check if there're illigal charcters 
	m.EmailIsOk = .F.
CASE OCCURS("@", m.EmAddr) <> 1
	* Only one '@' 
	m.EmailIsOk = .F.
CASE OCCURS(".", m.EmAddr) < 1
	* At least one dot 
	m.EmailIsOk = .F.
CASE OCCURS("..", m.EmAddr) > 0
	* No double dot 
	m.EmailIsOk = .F.
CASE OCCURS(".", m.Domain) < 1
	* At least one dot after '@'
	m.EmailIsOk = .F.
CASE INLIST(LEFT(m.Domain,1), "-", ".")
	m.EmailIsOk = .F.
CASE INLIST(RIGHT(m.Domain,1), "-", ".")
	m.EmailIsOk = .F.
CASE INLIST(LEFT(m.MailBox,1), "-", ".")
	m.EmailIsOk = .F.
CASE INLIST(RIGHT(m.MailBox,1), "-", ".")
	m.EmailIsOk = .F.
CASE NOT BETWEEN(LEN(SUBSTR(m.Domain, RAT(".",m.Domain)+1)), 2,4) 
	* TLD between 2 and 4 characters . Doesn't cover '.museum'
	m.EmailIsOk = .F.
ENDCASE
RETURN m.EmailIsOk
I've to point out that it's Fox 2.6 code.

>How can I check a e-mail by adapting the idea below
>
> if field contains @
> = messagebox "valid e-mail"
> else
> = messagebox " not a valid e-mail"
>endif
--sb--
Previous
Reply
Map
View

Click here to load this message in the networking platform