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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem with checking string

Status
Not open for further replies.

rtnMichael

Programmer
Aug 5, 2002
152
US
hey,
I was wondering if anybody could help me in figuring out how to return an alert if the '@hotmail.com' part of an email isn't there. I have to have the '@hotmail.com' part exactly, not just to see if they have a valid email address. Anybody who does this form will have the same email server, so the '@blah' will be the same.
I'm not sure if I have it right, but I have some code started:

function check_email(spacestring)
ilen = len(spacestring)
i = 1
while i <= ilen
if mid(spacestring,i,13) = &quot;@hotmail.com&quot; then
spacestring = right(spacestring,i-1)
Response.Write(spacesrting)
end if
i = i+1
wend
end function


I'm not sure if it's right, but I would appreciate any little bit of help.

Thanks
M
 
fred = &quot;test@hotmail.com&quot;
if instr(fred,&quot;@hotmail.com&quot;) Then
Msgbox &quot;@hotmail exists&quot;
Else
msgbox &quot;Hotmail does not exist&quot;
End If

Regards
Steve Friday
 
ok, I'm not having too much fun with this, and I would assume it's simple enough. Here's my problem, I'm doing the:

fred = &quot;test@hotmail.com&quot;
if instr(fred,&quot;@hotmail.com&quot;) Then
Msgbox &quot;@hotmail exists&quot;
Else
msgbox &quot;Hotmail does not exist&quot;
End If

in a function at the top of my page. In the onclick for the button, I'm calling the function
check_email(form.txtEmail.value); It tells me that check_email isn't defined.
Am I just not seeing the obvious???
 
Can you show me more of the code, IE the function and the call to it

Regards
Steve Friday
 
ok here's the function I'm using:
function check_email(spacestring)
if instr(spacestring,&quot;@hotmail.com&quot;) Then
'do nothing, it's fine
Else
msgbox &quot;You need to have '@hotmail.com'&quot;
End If
End function

and here's the button:

<td width=300 align=&quot;center&quot;><input type='button' name='btnSubmit' value='Submit' onclick='checkvalues(form); check_email(form.txtEmail.value);'>

the checkvalues just does validation.

this is what I get:
&quot;check_email is not defined.&quot;

Thanks
M
 
I had to change things a bit, not really a web person myself.

Sub btnSubmit_OnClick
If instr(frmadd.Email.Value,&quot;@hotmail.com&quot;) Then
'do nothing, it's fine
Else
msgbox &quot;You need to have '@hotmail.com'&quot;
End If
End Sub

changed you submit button to


<input type='button' name='btnSubmit' value='Submit'>

wasn't sure what the rest of it did some cleared it .

Hope this helps


Regards
Steve Friday
 
sorry that should have read!!

Sub btnSubmit_OnClick
If instr(form.txtEmail.value,&quot;@hotmail.com&quot;) Then
'do nothing, it's fine
Else
msgbox &quot;You need to have '@hotmail.com'&quot;
End If
End Sub
Regards
Steve Friday
 
ok, I did all that you said, but in the button, I needed an 'onclick' portion. this is exactly what I put for the button:
<input type='button' name='btnSubmit' value='Submit' onclick='btnSubmit_OnClick;'>

that would be the sub call when clicked. I still got the &quot;btnSubmit_OnClick is not defined&quot;

Am I making this harder than it really is???

Thanks
M
 
Pass it is beyond me - I don't know what the onclick= does, cannot find it in my manuals - guess I need to buy more - why do you need the onclick=???

Regards
Steve Friday
 
the onclick sends the command for the button to do what you want it to do. Like if you wanted to just submit, you would type onclick='submit'....I had to do some validations, so I did onclick='check_validations();' in the button.

I hope I've cleared it up. Other than knowing that, I have no idea why it's not working!!!
 
Doesn't the sub work when it has the name of the button??

Sub btnSubmit_OnClick

Bear in mind I am learning here myself!!

Regards
Steve Friday
 
This is how I tested, save this as html

<head>
<title>Post</title>
<SCRIPT LANGUAGE=&quot;vbscript&quot;>

Sub btnSubmit_OnClick

if instr(frmadd.Email.Value,&quot;@hotmail.com&quot;) Then
'do nothing, it's fine
Else
msgbox &quot;You need to have '@hotmail.com'&quot;
End If
End Sub




</Script>

</head>
<body>
<body topmargin=&quot;0&quot; leftmargin=&quot;0&quot;>
<div align=&quot;center&quot;>
<center>

</center>
</div>

<div align=&quot;center&quot;>
<center>
<table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;border-collapse: collapse&quot; bordercolor=&quot;#111111&quot; width=&quot;45%&quot; id=&quot;AutoNumber1&quot; bgcolor=&quot;#CCCCFF&quot;>
<tr>
<td width=&quot;100%&quot; bgcolor=&quot;#FFFFFF&quot;><span lang=&quot;en-gb&quot;><b>
<font face=&quot;Verdana&quot;>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</font></b></span></td>

<td width=&quot;100%&quot; bgcolor=&quot;#FFFFFF&quot;>
<p align=&quot;left&quot;><font face=&quot;Verdana&quot;><b><span lang=&quot;en-gb&quot;><font size=&quot;2&quot;>
Name: </font></span>
<form action=&quot;Addition.asp&quot; Method=post Name=&quot;frmadd&quot;>
<input type=&quot;text&quot; name=&quot;Email&quot; size=&quot;30&quot; tabindex=&quot;2&quot;><font size=&quot;2&quot;><br>
<br><span lang=&quot;en-gb&quot;>Message:</span><br>

<input type='button' name='btnSubmit' value='Submit'>


</td>


<td width=&quot;100%&quot; bgcolor=&quot;#FFFFFF&quot;><span lang=&quot;en-gb&quot;><b>
<font face=&quot;Verdana&quot;>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</font></b></span></td>
</tr>
</table>
</center>
</div>
</form>
</body>
</html> Regards
Steve Friday
 
actually, doesn't it work for MS Access? I know I've done some database stuff, and on the coding part, the properties refer to the btn_Onclick. I need to explicitly tell the button what it's going to do. Tha name of the button is only that...the name. I have yet to do anything with the name of the button. I'm pretty sure it has some sort of value, but without the 'onclick', it goes nowhere, just looks pretty :)


M
 
ok, it worked, and I guess I was wrong in the button thing. I'm going to try it out in my ASP file....maybe it's because it's an ASP file that it doesn't work. I'll try it out and let you know.

Thanks
M
 
ok, that worked, but how do I do it to stay on that page. The validation goes ok, but it still processes the next page. How do I stop it???

M
 
refer to this thread

thread329-385294

Regards
Steve Friday
 
rtnMichael,

This string, instr(form.txtEmail.value,&quot;@hotmail.com&quot;) does not return a Boolean value. It returns the starting position > 0 if true. Therefore you need to use

If instr(form.txtEmail.value,&quot;@hotmail.com&quot;) > 0 then


fengshui_1998
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top