Microsoft Small Basic

Program Listing: SKG602
'Email Format Validity checker created by Leonardo "Kroltan Bahuman" Giovanni Scur
'for the Small Basic Challenge of the Month in May 2013

'--------------- SUBROUTINES
'Check uses the email variable to verfy validty
Sub CheckMail
If (Text.IsSubText(email, "@")) Then 'check if can be divided
mailDomain = Text.GetSubTextToEnd(email, Text.GetIndexOf(email, "@")+1) 'get user part of email
If (Text.GetLength(mailDomain) > 0 And Text.IsSubText(mailDomain, ".") And mailDomain <> ".") Then
param1MakeArray = mailDomain
MakeArray()
param1InMask = emailMask
param2InMask = resultMakeArray
InMask()
If (resultInMask = 1) Then
mailUser = Text.GetSubText(email, 1, Text.GetIndexOf(email, "@")-1)
If (Text.GetLength(mailUser) > 0) Then
param1MakeArray = mailUser
MakeArray()
param1InMask = emailMask
param2InMask = resultMakeArray
InMask()
If (resultInMask = 1) Then
status = "This email aderess is valid"
Else
status = "Invalid email: unexpected symbol"
EndIf
Else
status = "Invalid email: no user specified"
EndIf
Else
status = "Invalid email: unexpected symbol"
EndIf
Else
status = "Invalid email: bad domain"
EndIf
Else
status = "Invalid email: not email format"
EndIf
EndSub

'MakeArray takes 1 input text and convert to a array of single characters
param1MakeArray = ""
Sub MakeArray
resultMakeArray = ""
For i = 0 To Text.GetLength(param1MakeArray)
resultMakeArray[i] = Text.GetSubText(param1MakeArray, i, 1)
EndFor
EndSub

'InMask takes 2 text array inputs (mask and content) and returns 1 if all the text is in the mask, else 0
'you can get text arrays using MakeArray
param1InMask = ""
param2InMask = ""
Sub InMask
resultInMask = 1
For i = 1 To Array.GetItemCount(param2InMask)
If (Array.ContainsValue(param1InMask, param2InMask[i]) = "False") Then
resultInMask = 0
EndIf
EndFor
EndSub

'--------------- MAIN CODE
emailMask = "abcdefghijklmnopqrstubwxyz1234567890_."
status = "Insert Email"
param1MakeArray = emailMask
MakeArray()
emailMask = resultMakeArray
start:
email = ""
GraphicsWindow.Title = "Kroltan's CotM - Email validation"
GraphicsWindow.Width = 220
GraphicsWindow.Height = 70
GraphicsWindow.BrushColor = "Black"
GraphicsWindow.BackgroundColor = "White"
GraphicsWindow.PenWidth = 0
GraphicsWindow.DrawText(5, 35, status)
emailBox = Controls.AddTextBox(5, 5)
Controls.SetSize(emailBox, 210, 25)
While "True"
email = Controls.GetTextBoxText(emailBox)
CheckMail()
GraphicsWindow.BrushColor = "White"
GraphicsWindow.FillRectangle(0, 30, 220, 40)
GraphicsWindow.BrushColor = "Black"
GraphicsWindow.DrawText(5, 35, status)
Program.Delay(100)
EndWhile