Microsoft Small Basic

Program Listing: LLJ836
char = "abcdefghijklmnopqrstuvwxyz0123456789_" 'valid char's except "@" and "."
enterAgain = "y"

While enterAgain = "y"
TextWindow.Write("Enter Email Address: ")
email = Text.ConvertToLowerCase(TextWindow.Read())
length = Text.GetLength(email)
ampIndex = Text.GetIndexOf(email, "@")
dotIndex1 = Text.GetIndexOf(email, ".")
If length >= 5 And Text.IsSubText(email, "@") = "True" And Text.IsSubText(email, ".") = "True" Then
For i = 1 To ampIndex-1
CheckString()
EndFor
For i = (ampIndex +1) To dotIndex1-1
CheckString()
EndFor
For i = (dotIndex1+1) To length
CheckString()
EndFor
Results()
Else
result[1] = "Invalid"
Results()
EndIf
Repeat()
EndWhile

Sub CheckString
If Text.IsSubText(char, Text.GetSubText(email, i, 1)) <> "True" Then
result[i] = "Invalid"
EndIf
EndSub

Sub Results
If Array.ContainsValue(result, "Invalid") = "True" Then
TextWindow.ForegroundColor = "Red"
TextWindow.WriteLine("Email Address is INVALID")
Else
TextWindow.ForegroundColor = "Green"
TextWindow.WriteLine("Email Address is VALID")
EndIf
TextWindow.ForegroundColor = "gray"
'TextWindow.WriteLine(result) 'if you uncomment this line you can see what's in the array
For i = 1 To Array.GetItemCount(result)
result[i] = "" 'empties the array before it is used again
EndFor
EndSub

Sub Repeat
TextWindow.WriteLine("")
TextWindow.Write("Enter another? y ")
enterAgain = Text.ConvertToLowerCase(TextWindow.ReadKey())
TextWindow.Clear()
EndSub