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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

contactkarthiCommented:
use reg exp to validate :)

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

new javax.mail.internet.InternetAddress( emailID )
0
ksivananthCommented:
if it is invalid, it will through AddressException!
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

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
contactkarthiCommented:
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
contactkarthiCommented:
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
contactkarthiCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.