473,836 Members | 1,510 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

I need javascript code for validate the email address

5 New Member
I need javascript code for validate the email address.

Email address field cannot allowed the capital letters, special characters except '@' symbol.

But can allowed the small letters, numeric numbers.

Now i use this script for validate the email address. But it allows the cpital letters otherwise its working correctly.

SCRIPT FUNCTION
*************** *************** *************** ***
Expand|Select|Wrap|Line Numbers
  1. function validateEmail(addr,man,db) {
  2.     if (addr == '' && man) {
  3.        if (db) alert('Email address is mandatory');
  4.        return false;
  5.     }
  6.     var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
  7.     for (i=0; i<invalidChars.length; i++) {
  8.        if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
  9.           if (db) alert('Email address contains invalid characters');
  10.           return false;
  11.        }
  12.     }
  13.     for (i=0; i<addr.length; i++) {
  14.        if (addr.charCodeAt(i)>127) {
  15.           if (db) alert("Email address contains non ascii characters.");
  16.           return false;
  17.        }
  18.     }
  19.     var atPos = addr.indexOf('@',0);
  20.     if (atPos == -1) {
  21.        if (db) alert('Email address must contain an @');
  22.        return false;
  23.     }
  24.     if (atPos == 0) {
  25.        if (db) alert('Email address must not start with @');
  26.        return false;
  27.     }
  28.     if (addr.indexOf('@', atPos + 1) > - 1) {
  29.        if (db) alert('Email address must contain only one @');
  30.        return false;
  31.     }
  32.     if (addr.indexOf('.', atPos) == -1) {
  33.        if (db) alert('Email address must contain a period in the domain name');
  34.        return false;
  35.     }
  36.     if (addr.indexOf('@.',0) != -1) {
  37.        if (db) alert('period must not immediately follow @ in email address');
  38.        return false;
  39.     }
  40.     if (addr.indexOf('.@',0) != -1){
  41.        if (db) alert('period must not immediately precede @ in email address');
  42.        return false;
  43.     }
  44.     if (addr.indexOf('..',0) != -1) {
  45.        if (db) alert('two periods must not be adjacent in email address');
  46.        return false;
  47.     }
  48.     var suffix = addr.substring(addr.lastIndexOf('.')+1);
  49.     if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
  50.        if (db) alert('invalid primary domain in email address');
  51.        return false;
  52.     }
  53. return true;
  54. }
*************** *************** *******
I need script for not allowed the capital letters.

Please any one can help me to rectify the email validation problem.
Apr 18 '08 #1
1 3145
gits
5,390 Recognized Expert Moderator Expert
you may use a regExp for this:

Expand|Select|Wrap|Line Numbers
  1. var foo = 'yourValue';
  2.  
  3. var val = /[A-Z]/g.test(foo);
  4.  
  5. // val is now true since we have a capital 'V'
kind regards
Apr 18 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

17
4934
by: Sue | last post by:
<html> Is there someone here that can help me validate the period as the fourth from the last character in an email address. There is other information and validation on the form I have to do but the period in the email address is the only part I am having problems with. I have posted part of my code below. Any help would be greatly appreciated. THANKS !
8
1978
by: Sue | last post by:
Hello! I am back with another question. Remember I am a new JavaScript student and I am aware that this code does not check for all the possibilities and that as a "NEW" JavaScript student I am not expected to check for everything. At any rate, the problem I am having with the following code is that it does not clear the fields once I press the SEND button. So can anyone here enlighten me as to what is causing the problem.
7
3631
by: x muzuo | last post by:
Hi guys, I have got a prob of javascript form validation which just doesnt work with my ASP code. Can any one help me out please. Here is the code: {////<<head> <title>IIBO Submit Page</title> </head> <style type="text/css">
4
10156
by: usl2222 | last post by:
Hi folks, I appreciate any assistance in the following problem: I have a form with a bunch of dynamic controls on it. All the controls are dynamically generated on a server, including all the validators. The user enters the data, presses OK. My OK button is dynamically generated as well, with some code-behind logic in
2
2372
by: daniel.boorn | last post by:
Form validation using JavaScript has never been as easy and simple! We have developed a free generic form validation script that can validate any form with very little JavaScript required in form! For example: A normal HTML form with out validation: <form action="foobar.htm" method="get"> <div>Name: <input type="text" name="customerName" value=""></div>
27
4774
by: Chris | last post by:
Hi, I have a form for uploading documents and inserting the data into a mysql db. I would like to validate the form. I have tried a couple of Javascript form validation functions, but it appears that the data goes straight to the processing page, rather than the javascript seeing if data is missing and popping up an alert. I thought it may be because much of the form is populated with data from the db (lists, etc.), but when I leave...
1
1841
by: pstephen01010101 | last post by:
I've ran out of debugging ideas. If anyone knows why this won't run in IE 6 please let me know. It works fine in Fire Fox 2.0.0.3 and Netscape (version unknown). I suspect there is something basic about IE and Javascript that I'm wholly unaware of. I've edited the HTML code to include just the essential elements because it exceeded the allowed word count. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
5
2644
by: ghjk | last post by:
I have a web site with several web pages. They are having different number of variables. eg: first page having 4 variables in the form(Name, Phone, ID, Gender) second page having 10 variables in the form(eg: Name, Age, Time, etc.) I want to validate each and every variable. So how can I do that? I found this JavaScript.But in this case for each and every variable I have to write a function.Eg:for each and every variable i have to rewrite the...
1
2848
by: irfanshariffa | last post by:
<html> <head> <script type="text/javascript" language="javascript"> function validate() { if (document.form.fname.value=="") { alert("Enter your Name"); document.form.fname.focus();
0
10854
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10558
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10257
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9387
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6981
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4459
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4022
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3116
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.