document.write('<div class="c" style="font-family: monospace;"><br />');
document.write('<span style="color: #000000; font-weight: bold;">Function</span> IsValidEmail<span style="color: #66cc66;">&#40;</span>emailAddress<span style="color: #66cc66;">&#41;</span><br />');
document.write('<span style="color: #ff0000;">\'Declare variables <br />');
document.write('<br />');
document.write('Dim ValidEmail, emailParts, iLoopCounter, emailChar, acceptableChars<br />');
document.write('&nbsp; &nbsp; &nbsp;ValidEmail = True \'</span>set the <span style="color: #b1b100;">default</span> result to <span style="color: #000000; font-weight: bold;">True</span><br />');
document.write('<br />');
document.write('&nbsp; &nbsp; &nbsp;<span style="color: #ff0000;">\'acceptableChars are the characters that we will allow in our email<br />');
document.write('<br />');
document.write('&nbsp; &nbsp; &nbsp;acceptableChars=&quot;abcdefghijklmnopqrstuvwxyz.-_@&quot;<br />');
document.write('&nbsp; &nbsp; &nbsp;\'</span>use the Split <span style="color: #000000; font-weight: bold;">function</span> to create an array with the @ as the separator<br />');
document.write('<br />');
document.write('&nbsp; &nbsp; &nbsp;<span style="color: #ff0000;">\'so if your email was test@tester.com the email would be split into an array<br />');
document.write('<br />');
document.write('&nbsp; &nbsp; &nbsp;\'</span>with the first array element holding <span style="color: #ff0000;">&quot;test&quot;</span> and the second <span style="color: #ff0000;">&quot;tester.com&quot;</span><br />');
document.write('<br />');
document.write('&nbsp; &nbsp; &nbsp;emailParts = Split<span style="color: #66cc66;">&#40;</span>emailAddress, <span style="color: #ff0000;">&quot;@&quot;</span><span style="color: #66cc66;">&#41;</span><br />');
document.write('&nbsp; &nbsp; &nbsp;<span style="color: #ff0000;">\'check to make sure that there is only 1 @ and that there are 2 parts<br />');
document.write('<br />');
document.write('&nbsp; &nbsp; &nbsp;\'</span>remember arrays are zero based<br />');
document.write('<br />');
document.write('&nbsp; &nbsp; &nbsp;<span style="color: #ff0000;">\'Using the UBound function will return the highest element in the array<br />');
document.write('<br />');
document.write('&nbsp; &nbsp; &nbsp;\'</span>So <span style="color: #b1b100;">if</span> it<span style="color: #ff0000;">\'s a valid email the UBound function will return 1, i.e. 0 start<br />');
document.write('<br />');
document.write('&nbsp; &nbsp; &nbsp;if UBound(emailParts) &lt;&gt; 1 Then<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ValidEmail = false<br />');
document.write('&nbsp; &nbsp; &nbsp;Else <br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \'</span>Check the length of each part of the email address<br />');
document.write('<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">\'first part can be just one character, 2nd part must be atleast 4<br />');
document.write('<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if Len(emailParts(0))&lt;1 OR Len(emailParts(1))&lt;4 Then<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ValidEmail = false<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End If<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \'</span>check first character on the left part isn<span style="color: #ff0000;">\'t a &quot;.&quot; using Left function<br />');
document.write('<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if Left(emailParts(0), 1)=&quot;.&quot; Then<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ValidEmail = false<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End If<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \'</span>check the last &amp; 2nd character from right part using Right <span style="color: #000000; font-weight: bold;">function</span> <br />');
document.write('<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> Right<span style="color: #66cc66;">&#40;</span>emailParts<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>, <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> = <span style="color: #ff0000;">&quot;.&quot;</span> OR Right<span style="color: #66cc66;">&#40;</span>emailParts<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>, <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span> = <span style="color: #ff0000;">&quot;.&quot;</span> Then<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ValidEmail = <span style="color: #000000; font-weight: bold;">false</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End <span style="color: #b1b100;">If</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">\'check that there is a . in the second part of the email address - .com<br />');
document.write('<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if InStr(emailParts(1), &quot;.&quot;) &lt;= 0 Then<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ValidEmail = false <br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End if <br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \'</span>check that there shouldn<span style="color: #ff0000;">\'t be a _ in the second part of the email address <br />');
document.write('<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if InStr(emailParts(1), &quot;_&quot;) &gt;0 Then<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ValidEmail = false <br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End if <br />');
document.write('&nbsp; &nbsp; &nbsp;End If<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \'</span>loop through each character of email<br />');
document.write('<br />');
document.write('&nbsp; &nbsp; &nbsp;<span style="color: #b1b100;">For</span> iLoopCounter = <span style="color: #cc66cc;">1</span> to Len<span style="color: #66cc66;">&#40;</span>emailAddress<span style="color: #66cc66;">&#41;</span><br />');
document.write('&nbsp; &nbsp; &nbsp;<span style="color: #ff0000;">\'Use Lcase &amp; Mid functions, Mid function used to return each individual character<br />');
document.write('<br />');
document.write('&nbsp; &nbsp; &nbsp;\'</span>in the email, and then Lcase converts it into lowercase<br />');
document.write('<br />');
document.write('&nbsp; &nbsp; &nbsp;emailChar = Lcase<span style="color: #66cc66;">&#40;</span>Mid<span style="color: #66cc66;">&#40;</span>emailAddress, iLoopCounter, <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <br />');
document.write('&nbsp; &nbsp; &nbsp;<span style="color: #ff0000;">\'Check if the emailAddress characters are acceptable<br />');
document.write('<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if InStr(acceptableChars, emailChar) = 0 and Not IsNumeric(emailChar) Then<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ValidEmail = false<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End if<br />');
document.write('&nbsp; &nbsp; &nbsp;Next<br />');
document.write('&nbsp; &nbsp; &nbsp;\'</span>check <span style="color: #b1b100;">if</span> there is <span style="color: #cc66cc;">2</span> . <span style="color: #202020;">in</span> a row<br />');
document.write('<br />');
document.write('&nbsp; &nbsp; &nbsp;<span style="color: #b1b100;">if</span> InStr<span style="color: #66cc66;">&#40;</span>emailAddress, <span style="color: #ff0000;">&quot;..&quot;</span><span style="color: #66cc66;">&#41;</span> &gt; <span style="color: #cc66cc;">0</span> Then<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ValidEmail=<span style="color: #000000; font-weight: bold;">false</span><br />');
document.write('&nbsp; &nbsp; &nbsp;End <span style="color: #b1b100;">If</span><br />');
document.write('&nbsp; &nbsp; &nbsp;<span style="color: #ff0000;">\'check if there is @. in a row<br />');
document.write('<br />');
document.write('&nbsp; &nbsp; &nbsp;if InStr(emailAddress, &quot;@.&quot;) &gt; 0 Then<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ValidEmail=false<br />');
document.write('&nbsp; &nbsp; &nbsp;End if <br />');
document.write('&nbsp; &nbsp; &nbsp;IsValidEmail=ValidEmail<br />');
document.write('End function<br />');
document.write('&nbsp;</span></div>');
document.write('<br />&nbsp;<br /><div style="font-size: 12px">Brought to you by the community at <a href="http://www.bytemycode.com/snippets/snippet/114/1/" target="_blank">byteMyCode</a>.</div>');
