473,246 Members | 1,337 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,246 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 3072
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();
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.