• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

email validation

 
Ranch Hand
Posts: 517
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi..

can anyone help me to validate my forms email adress field.
i am using this code.. but it doesnt work


function validEmail(_form,_action)
{

if(document.euserForm.popUserID.value=="")
{
alert("Enter your email id");
return
}
else
{
if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.euserForm.popUserID.value)))
{

alert("The email you entered is not a valid email address.");
return
}
 
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was at a course last month on javascript and one of the things I got was email validation, I kept this just incase I needed it again. maybe you could change your regexp string to:
/(\w*\@\w*\.\w{3})|(\w*\@\w*\.\w{2}\.\w{2})|(\w*\.\w*\@\w*\.\w{3})|(\w*\.\w*\@\w*\.\w{2}\.\w{2})/g

Davy
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Recognizing e-mail addresses is hard, bordering on impossible. The only real reference to what an e-mail address can look like is the SMTP specification (RFC 2821), and that is very forgiving. Anything on the form <localpart>@<domain> is acceptable.

I usually recommend going with just:


That accepts all of these (perfectly valid) addresses:
  • me+something@example.com
  • me.something@[192.168.10.2]
  • "Mr.Jones"@example.com


  • The parts before the "@" should only ever be interpreted by the
    receiving host, so you shouldn't try to rule something out (except
    extra "@"'s). The part after the "@" can be a domain name or an
    IP-address (both IPv4 and IPv6).

    Also remember, that there is no way to ensure that an e-mail address works, i.e., that it can receive mail, except trying to send to it and receive an answer. On the other hand, it is far too easy to reject a perfectly good and working address, which will make the user of the page a lot of pain and cursing ... not something to aim for.

    Aim to accept too much rather than too little. The worst that can happen is that the mail bounces or is lost, and that will probably happen for foo@example.com too.

    /L
     
    Do not meddle in the affairs of dragons - for you are crunchy and good with ketchup. Crunchy tiny ad:
    Gift giving made easy with the permaculture playing cards
    https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
    reply
      Bookmark Topic Watch Topic
    • New Topic