Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

emial validation (again) 1

Status
Not open for further replies.

mad411

Technical User
Apr 4, 2002
17
IN
hey
thanx to u all

i've been to the site


where i found this asp code for email validation


<html>
<head>
<title>VBscript email validation</title>
</head>
<body>
<%
Dim emailAddress
emailAddress = Request(&quot;emailAddress&quot;)
if emailAddress <> &quot;&quot; then
emailAddress = Cstr(emailAddress)
if emailAddress <> &quot;&quot; then
blnValidEmail = RegExpTest(emailAddress)
if blnValidEmail then
Response.Write(&quot;Valid email address&quot;)
else
Response.Write(&quot;Not a valid email address&quot;)
end if
end if

Function RegExpTest(sEmail)
RegExpTest = false
Dim regEx, retVal
Set regEx = New RegExp

' Create regular expression:
regEx.Pattern =&quot;^[\w]{1,}\@([\da-zA-Z-]{1,}\.){1,}[\da-zA-Z-]{2,3}$&quot;

' 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
Else
%>

<form>
<input type=&quot;text&quot; name=&quot;emailAddress&quot;>
<input type=&quot;submit&quot; value=&quot;submit&quot;>
</form>

<%End If %>

</body>
</html>

well this code runs well in .asp file
i modified this code so that it can be used in .html file
the code i modified is as follows


<html>
<head>
<title>VBscript email validation</title>
</head>
<body>
<script language=&quot;vbscript&quot;>
<!--
Sub btn_reg_onclick
Dim emailAdd
emailAdd = form1.emailAddress
if emailAdd <> &quot;&quot; then
emailAdd = Cstr(emailAdd)
if emailAdd <> &quot;&quot; then
blnValidEmail = RegExpTest(emailAdd)
if blnValidEmail then
alert &quot;Valid email address&quot;
else
alert &quot;Not a valid email address&quot;
end if
end if
RegExpTest(sEmail)
Else
msgbox &quot;hi&quot;
End If
End Sub

Function RegExpTest(sEmail)
RegExpTest = false
Dim regEx, retVal
Set regEx = New RegExp

' Create regular expression:
regEx.Pattern =&quot;^[\w]{1,}\@([\da-zA-Z-]{1,}\.){1,}[\da-zA-Z-]{2,3}$&quot;

' 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
-->
</script>
<form name=&quot;form1&quot;>
Enter e-Mail Address<input type=&quot;text&quot; name=&quot;emailAddress&quot;><br>
<input name=&quot;btn_reg&quot; type=&quot;submit&quot; value=&quot;Click To Register&quot;>
</form>
</body>
</html>



when i run the above .html file & if i enter invalid email
address it shows proper alert message but if i enter a valid email address then also it shows the same message i.e &quot;not a valid email address&quot; why is that happening??
also it is not giving the &quot;hi&quot; message


can u help me out with this code please
i know that there is a mistake in the code but i cant figure out what
 
You'll probably hate me for saying this but if you need to validate the email client side using Javascript would be a easier way to do it. Thats a person preference though and I don't know your needs for the work. Here's a good example of email val. in javascript in case you can use it. I've tried to get the code you found working also with no success.
<html>
<head><title>Email validation example</title>

<script Language=&quot;JavaScript&quot;>
function isEmailAddr(email)
{
var result = false
var theStr = new String(email)
var index = theStr.indexOf(&quot;@&quot;);
if (index > 0)
{
var pindex = theStr.indexOf(&quot;.&quot;,index);
if ((pindex > index+1) && (theStr.length > pindex+1))
result = true;
}
return result;
}

function FormValidator(theForm)
{

if (theForm.email.value == &quot;&quot;)
{
alert(&quot;Please enter a value for the \&quot;email\&quot; field.&quot;);
theForm.email.focus();
return (false);
}

if (!isEmailAddr(theForm.email.value))
{
alert(&quot;Please enter a complete email address in the form: yourname@yourdomain.com&quot;);
theForm.email.focus();
return (false);
}

if (theForm.email.value.length < 3)
{
alert(&quot;Please enter at least 3 characters in the \&quot;email\&quot; field.&quot;);
theForm.email.focus();
return (false);
}
return (true);
}
</script>
</head>
<body>
<form method=&quot;POST&quot; action=&quot;blemailvalidate.htm&quot; onsubmit=&quot;return FormValidator(this)&quot; id=form4 name=form4>
<p>Email Address: <input type=&quot;text&quot; name=&quot;email&quot; size=&quot;32&quot;><input type=&quot;submit&quot;
value=&quot;Submit&quot; name=&quot;submit&quot;></p>
</form>
</body> provide tools to let people become their best.
 
hey [afro]


hey thanx a lot onpnt, here's a medal for u [medal]
i've already marked ur post as an helpful & expert post

i tried your code & it really works well, [2thumbsup]
but if i type xyz@xyz.c or xyz@xyz.c.o.m
then also it works. [sad] sorry for being so pushy
towards vbscript

actually i m still learning vbscript and i dont have any
idea about java script. I dont have java script in my course so it is very imp for me to do the validation in vbscript only.i want the coding for my class project.


can u check the coding i sent once again please
i m sure u'll find out the mistake in it



[noevil]
 
hey onpnt [2thumbsup]

i found the mistake (at last) [idea]

in the above .html file where i was writing

....
........
if emailAdd <> &quot;&quot; then
blnValidEmail = RegExpTest(emailAdd)
if blnValidEmail then
alert &quot;Valid email address&quot;
else
alert &quot;Not a valid email address&quot;
end if
end if
........
.....

i should have simply written
....
........
if emailAdd <> &quot;&quot; then
blnValidEmail = RegExpTest(form1.emailAddress.value)
if blnValidEmail then
alert &quot;Valid email address&quot;
else
alert &quot;Not a valid email address&quot;
end if
end if
........
.....


so dumb of me [conehead]

thanx for ur support, it helped me a lot



[noevil]
 
ok I have a question regarding the javascript..Once the user hits submit. How do you make the button and textbox to go away and write a message on the screen saying thank you for subscribing so that they do not submit over and over again...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top