email validation

when we want to check if the inserted data is a valid email we need to check if there is a @ inside...
but we also need to check if after the @ comes a word and after it comes a point(.)
and after it may be another word with point...and so on 3 times...
for example
sash85@mailer.ru.ua


i am sure you have done it so many times:)
can you help to match it to my script here:
*my text input name is 'tomail'

function validate5(){
      if (!validate4()) return false;
      if (document.reportgen.tomail.value == "") {
         alert(document.getElementById('fillmail').innerHTML);
         return false;
      }
      return true;
};

Open in new window

sasha85Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
contactkarthiConnect With a Mentor Commented:
just confused...

change the button as

response.write "<br><a href=""#"" onClick=""if(validate5()  && emailCheck ()){document.reportgen.action='ptomail.asp?rep=1';document.reportgen.submit();}"">submit</a>"

the start of the emailCheck function in the link as

function emailCheck () {
var  emailStr = document.reportgen.tomail.value ;
0
 
contactkarthiConnect With a Mentor Commented:
use reg exp to validate :)

http://www.devx.com/tips/Tip/28334
0
 
ksivananthConnect With a Mentor Commented:
just do this, which will validate the most of the RFC822 spec for you,

new javax.mail.internet.InternetAddress( emailID )
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
ksivananthCommented:
if it is invalid, it will through AddressException!
0
 
sasha85Author Commented:
javascript:
function validate5(){
      if (!validate4()) return false;
      if (document.reportgen.tomail.value == "") {
         alert(document.getElementById('fillmail').innerHTML);
         return false;
      }
      return true;
};

can you please show how i combine with
something like this
http://www.devx.com/tips/Tip/28334
but not just hotmail...any mailer...
0
 
contactkarthiCommented:
do you want a javascritp fuction?
0
 
contactkarthiConnect With a Mentor Commented:
if you want java script use the one from this page

http://javascript.internet.com/forms/check-email.html

there is a field to ttest the script
0
 
sasha85Author Commented:
wow! this is one long script...i will use it...
the operator comand is "onsubmit" , i cant use it on the in the <form...>
<form name=emailform onSubmit="return emailCheck(this.email.value);">
can i somehow operat it from
my submit button:
response.write "<br><a href=""#"" onClick=""if(validate5() ){document.reportgen.action='ptomail.asp?rep=1';document.reportgen.submit();}"">submit</a>"
?
0
 
contactkarthiConnect With a Mentor Commented:
the script takes care of almost all the validation.. also the script is huge because of the amount of comments it has.

all the script is a single function that takes email as input and return true or false..
0
 
sasha85Author Commented:
that part i understand...i asked how i can call this script from my script above or from the submit button
0
 
contactkarthiCommented:

<INPUT TYPE="button" NAME="button" Value="Submit" onClick="your script code goes here">

0
 
sasha85Author Commented:
i will explain again:

here is my button:
response.write "<br><a href=""#"" onClick=""if(validate5() ){document.reportgen.action='ptomail.asp?rep=1';document.reportgen.submit();}"">submit</a>"

how can i add the operator to that script:
http://javascript.internet.com/forms/check-email.html
into my button
?
0
 
sasha85Author Commented:
where?
var  emailStr = document.reportgen.tomail.value ;

i studied this script a little...there is so much things i can't understand there...
for exmaple why we need this ip check?



 
<SCRIPT LANGUAGE="Javascript">
 
function emailCheck (emailStr) {
 
var emailPat=/^(.+)@(.+)$/
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
 
var validChars="\[^\\s" + specialChars + "\]"
 
var quotedUser="(\"[^\"]*\")"
 
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
 
var atom=validChars + '+'
 
var word="(" + atom + "|" + quotedUser + ")"
 
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
 
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
 
 
var matchArray=emailStr.match(emailPat)
if (matchArray==null) {
 
	alert("Email address seems incorrect (check @ and .'s)")
	return false
}
var user=matchArray[1]
var domain=matchArray[2]
 
 
if (user.match(userPat)==null) {
    // user is not valid
    alert("The username doesn't seem to be valid.")
    return false
}
 
 
var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
	        alert("Destination IP address is invalid!")
		return false
	    }
    }
    return true
}
 
var domainArray=domain.match(domainPat)
if (domainArray==null) {
	alert("The domain name doesn't seem to be valid.")
    return false
}
 
 
var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 || 
    domArr[domArr.length-1].length>3) {
   alert("The address must end in a three-letter domain, or two letter country.")
   return false
}
 
if (len<2) {
   var errStr="This address is missing a hostname!"
   alert(errStr)
   return false
}
 
 
return true;
}
 
</script>

Open in new window

0
 
sasha85Author Commented:
i thought about it...this script is too much heavy...can you suggest what we can drop?
i just need to check if the structure is email format...
@ word point word (ends with word and not point) and do not use the wrong chars...
0
All Courses

From novice to tech pro — start learning today.