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

Validate email address

Status
Not open for further replies.

ChrisRChamberlain

Programmer
Mar 23, 2000
3,392
GB
Hi all

The following Form to E-mail script submits standard user entered information, but has no email address validatation :-

<html>
<head>
<title>Your title</title>
</head>
<body>

<form method=&quot;post&quot; action=&quot;
<!--The title and URL of the form will be listed at the top of the e-mail-->
<input type=&quot;hidden&quot; name=&quot;Form title&quot; value=&quot;Source of form&quot;>

<!--Specify the e-mail address to which data from the form should be sent-->
<input type=&quot;hidden&quot; name=&quot;SendMailTo&quot; value=&quot;youremailname@btinternet.com&quot;>

<!--Specify the acknowledgement page to be seen by customers who have sent in the form-->
<input type=&quot;hidden&quot; name=&quot;redirect&quot; value=&quot;
<h1>Form title here</h1>
<p>explanatory text here</p>

<pre>

<b>Name</b>
<input name=&quot;Name&quot;>

<b>E-mail address</b>
<input name=&quot;E-mail address&quot;>

<b>Other info</b>
<input name=&quot;Other info&quot;>

<b>Description</b>
<textarea name=&quot;Description of pages&quot; rows=5 cols=50></textarea>

<b>Radio buttons</b>
<input type=&quot;radio&quot; name=&quot;year&quot; value=&quot;1997&quot;> 1997
<input type=&quot;radio&quot; name=&quot;year&quot; value=&quot;1996&quot;> 1996
<input type=&quot;radio&quot; name=&quot;year&quot; value=&quot;1995&quot;> 1995
<input type=&quot;radio&quot; name=&quot;year&quot; value=&quot;1994&quot;> 1994

<b>Check boxes</b>

<input type=&quot;checkbox&quot; name=&quot;category&quot; value=&quot;choice A&quot;> Choice A <input type=&quot;checkbox&quot; name=&quot;category&quot; value=&quot;choice B&quot;> Choice B <input type=&quot;checkbox&quot; name=&quot;category&quot; value=&quot;choice C&quot;> Choice C <input type=&quot;checkbox&quot; name=&quot;category&quot; value=&quot;choice D&quot;> Choice D </pre>
<hr>
<center>
<input type=&quot;submit&quot; value=&quot;Submit&quot;> <input type=&quot;Reset&quot; value=&quot;Start Again&quot;>
</center>
</form>
</body>
</html>

The following script validates an email address :-

<form name=&quot;validation&quot; onSubmit=&quot;return checkbae()&quot;>
Please input a valid email address:<br>
<input type=&quot;text&quot; size=18 name=&quot;emailcheck&quot;>
<input type=&quot;submit&quot; value=&quot;Submit&quot;>
</form>
<script language=&quot;JavaScript1.2&quot;>

//Advanced Email Check credit-
//By JavaScript Kit (//Over 200+ free scripts here!

var testresults
function checkemail(){
var str=document.validation.emailcheck.value
var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
if (filter.test(str))
testresults=true
else{
alert(&quot;Please input a valid email address!&quot;)
testresults=false
}
return (testresults)
}
</script>

<script>
function checkbae(){
if (document.layers||document.getElementById||document.all)
return checkemail()
else
return true
}
</script>

<p align=&quot;center&quot;><font face=&quot;arial&quot; size=&quot;-2&quot;>This free script provided by</font><br>
<font face=&quot;arial, helvetica&quot; size=&quot;-2&quot;><a href=&quot;Kit</a></font></p>

The question is, how can you integrate the code from the email validation routine into the original script?

Alternatively, what other code would work?

TIA


FAQ184-2483 - the answer to getting answered.​
Chris [pc2]
 
First, place the validation script between the <head></head> tags of your original file.

Then, replace the original files form tag: <form method=&quot;post&quot; action=&quot; with this:

<form method=&quot;post&quot; action=&quot; onSubmit=&quot;return checkbae()&quot;>;

There's always a better way. The fun is trying to find it!
 
tviman

Thanks for your response.

Unfortunately your suggestion does not work as is.

The function checkemail() requires a variable str derived from the form name 'validation' and the input name 'emailcheck' value.

In order to achieve that you have to add

'name=&quot;validation&quot;'

to the form, and change

<input name=&quot;E-mail address&quot;>

to

<input name=&quot;emailcheck&quot;> [smile]

FAQ184-2483 - the answer to getting answered.​
Chris [pc2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top