• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

How to validate email id using javascript?

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have created one form using struts 1 and hibernate. I want to validate email id field in that and the validation I have done using javascript.
This is the function I have used

function donationData(){

var EmailId = document.getElementById('emailId').value;

var filterEmail = /^([a-zA-Z0-9_\.])+\@(([a-zA-Z\-])+\.)+([a-zA-Z]{2,4})+$/;

if(!EmailId.match(filterEmail)) {
alert("Please Enter Valid Email Address");
return false;
}
}


This funtion properly validates for some conditions but for some conditions it is not validating properly.
For e.g. for email id

s@gmail.comwereterrrrrrrrrrrrrrrrrrrrrrrrrfdgfdgdf

it is accepting the value and returning true
I have searched a lot for this email validation but I am not getting any proper validation.
Please help me.
 
Marshal
Posts: 3653
516
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Look-over where you are using the + symbol, understanding that it means one-or-more matches of the bracketed expression (not concatenation of expressions).
 
Rancher
Posts: 43026
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This regexp will disallow many a valid email address: 1) The local part can contain numerous other characters than the ones listed, amongst them plus and minus. 2) It does not allow for internationalized domain names (IDNs) that need not be ASCII. 3) The TLD can be longer than 4 characters.
 
sarita chaudhary
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot all of you for your help
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic