473,395 Members | 1,774 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

I need javascript code for validate the email address

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 3090
gits
5,390 Expert Mod 4TB
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
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...
8
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...
7
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>...
4
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...
2
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!...
27
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...
1
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...
5
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...
1
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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
0
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,...

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.