I though this maybe useful to some. I saw it posted on line in Java and converted it to MS. It tests a variable to see if it is an email address.
It does not confirm the address only the format.
It makes sure there is an "@" symbol, one character before it and that it ends in a 2, 3, or four character extension after the last period.
//Test to see if an email address
//Test for @
//Test for Character before @
//Test to see that after the @ symbol it ends in a 2,3 or four extenssion after the period.
Let>deliveraddress=[email protected]
GoSub>validateemailadd
IF>test=YES
MDL>%deliveraddress% is an email address
Endif
IF>test=NO
MDL>%deliveraddress% is not an email address
Endif
SRT>validateemailadd
Position>@,%deliveraddress%,1,t
If>t=0,notanemail
Separate>%deliveraddress%,@,addarray
If>ADDARRAY_COUNT=2
Length>%ADDARRAY_1%,t
If>t=0,notanemail
Separate>ADDARRAY_2,.,suffex
Let>s=suffex_COUNT
If>%s%=0,notanemail
Let>ext=suffex_%s%
Length>%ext%,t
IF>{(%t% > 1) AND (%t% haveanemail
Endif
Else
Goto>notanemail
Endif
Label>notanemail
Let>test=NO
Goto>donetest
Label>haveanemail
Let>test=YES
Label>donetest
END>validateemailadd
test string for email address (validate an email address)
Moderators: Dorian (MJT support), JRL, Phil Pendlebury
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Regular Expressions are usually used for this sort of thing. Here's a VBScript function for validating an email address:
Test it with:
Code: Select all
VBSTART
Function RegExpTest(sEmail)
RegExpTest = false
Dim regEx, retVal
Set regEx = New RegExp
' Create regular expression:
regEx.Pattern ="^[\w-\.]{1,}\@([\da-zA-Z-]{1,}\.){1,}[\da-zA-Z-]{2,4}$"
' Set pattern:
regEx.IgnoreCase = true
' Set case sensitivity.
retVal = regEx.Test(sEmail)
' Execute the search test.
If not retVal Then
exit function
End If
RegExpTest = true
End Function
VBEND
Code: Select all
VBEval>RegExpTest("[email protected]"),isValid
MessageModal>isValid
VBEval>RegExpTest("bad_444%boo.do"),isValid
MessageModal>isValid
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?