Click to See Complete Forum and Search --> : validate multiple emails


gcook1
01-10-2006, 09:28 AM
I do a simple email check on some internal forms. I just check for the existance of the @ sign. Here's my problem... if someone enters multiple emails and only one is valid, my check says it's ok. Here's the code I use. strEmail is the textbox the user enters emails into.

function MyForm_OnSubmit
validation = True

If(document.MyForm.strEmail.Value) = "" Then
MsgBox("An E-mail address is required")
validation = False
Elseif(InStr(1,document.MyForm.strEmail.Value,"@",1)<2) Then
MsgBox("The To: Email address is invalid")
validation = False
End If

If validation = True Then
MyForm_OnSubmit = True
Else
MyForm_OnSubmit = False
End if

So how would you handle multiple email situations?

Breaker
01-10-2006, 10:42 AM
You've got to take the string enetered in strEmail and seperate the emails into seperate entities. In VBScript I'd dump it into an array using the split function, then loop through the array (having set the 'IsValidEmail' variable to true) and as soon as it encounters a false email address, set the IsValidEmail variable to false, drop out of the array loop, and throw up an error for the user.

Dim arrEmailList
Dim intArrayCount
Dim strInvalidEmail
Dim IsEmailValid

IsEmailValid = True

arrEmailList = Split(strEmail,","0
For intArrayCount = 0 to ubound(arrEmailList)
If Instr(arrEmailList(intArrayCount),"@")<1 Then
IsEmailValid = False
strInvalidEmail = arrEmailList(intArrayCount)
End If
Next

If IsEmailValid = False Then
MsgBox("The To: " & strInvalidEmail & " email address is invalid")
End If

Something like that....any use?

Bullschmidt
01-10-2006, 02:58 PM
And for a little more on the Split() function:

Parsing with join and split - 5/9/1999
http://www.4guysfromrolla.com/webtech/050999-1.shtml