Exforsys
+ Reply to Thread
Results 1 to 3 of 3

Java Script to validate email address

This is a discussion on Java Script to validate email address within the Java forums, part of the Programming Talk category; Guys I need java script to check if the users have entered valid email address or not. Kindly post them ...

  1. #1
    Raman is offline Junior Member Array
    Join Date
    Feb 2006
    Answers
    15

    Java Script to validate email address

    Guys

    I need java script to check if the users have entered valid email address or not.

    Kindly post them here

    Regards
    Raman


  2. #2
    Quozty is offline Junior Member Array
    Join Date
    Dec 2006
    Answers
    26
    <!-- Script by hscripts.com -->
    <script language=javascript>

    function checkMailId(mailids)
    {
    var arr = new Array('.com','.net','.org','.biz','.coop','.info','.museum','.name','.pro'
    ,'.edu','.gov','.int','.mil','.ac','.ad','.ae','.af','.ag','.ai','.al',
    '.am','.an','.ao','.aq','.ar','.as','.at','.au','.aw','.az','.ba','.bb',
    '.bd','.be','.bf','.bg','.bh','.bi','.bj','.bm','.bn','.bo','.br','.bs',
    '.bt','.bv','.bw','.by','.bz','.ca','.cc','.cd','.cf','.cg','.ch','.ci',
    '.ck','.cl','.cm','.cn','.co','.cr','.cu','.cv','.cx','.cy','.cz','.de',
    '.dj','.dk','.dm','.do','.dz','.ec','.ee','.eg','.eh','.er','.es','.et',
    '.fi','.fj','.fk','.fm','.fo','.fr','.ga','.gd','.ge','.gf','.gg','.gh',
    '.gi','.gl','.gm','.gn','.gp','.gq','.gr','.gs','.gt','.gu','.gv','.gy',
    '.hk','.hm','.hn','.hr','.ht','.hu','.id','.ie','.il','.im','.in','.io',
    '.iq','.ir','.is','.it','.je','.jm','.jo','.jp','.ke','.kg','.kh','.ki',
    '.km','.kn','.kp','.kr','.kw','.ky','.kz','.la','.lb','.lc','.li','.lk',
    '.lr','.ls','.lt','.lu','.lv','.ly','.ma','.mc','.md','.mg','.mh','.mk',
    '.ml','.mm','.mn','.mo','.mp','.mq','.mr','.ms','.mt','.mu','.mv','.mw',
    '.mx','.my','.mz','.na','.nc','.ne','.nf','.ng','.ni','.nl','.no','.np',
    '.nr','.nu','.nz','.om','.pa','.pe','.pf','.pg','.ph','.pk','.pl','.pm',
    '.pn','.pr','.ps','.pt','.pw','.py','.qa','.re','.ro','.rw','.ru','.sa',
    '.sb','.sc','.sd','.se','.sg','.sh','.si','.sj','.sk','.sl','.sm','.sn',
    '.so','.sr','.st','.sv','.sy','.sz','.tc','.td','.tf','.tg','.th','.tj',
    '.tk','.tm','.tn','.to','.tp','.tr','.tt','.tv','.tw','.tz','.ua','.ug',
    '.uk','.um','.us','.uy','.uz','.va','.vc','.ve','.vg','.vi','.vn','.vu',
    '.ws','.wf','.ye','.yt','.yu','.za','.zm','.zw');
    var mai = mailids;
    var val = true;

    var dot = mai.lastIndexOf(".");
    var ext = mai.substring(dot,mai.length);
    var at = mai.indexOf("@");
    var dom = dot - at;
    var sp = mai.indexOf(" ");

    if(dom >= 4 && at >1 && sp == -1)
    {
    for(var i=0; i<arr.length; i++)
    {
    if(ext == arr[i])
    {
    val = true;
    break;
    }
    else
    {
    val = false;
    }
    }
    if(val == false)
    {
    alert("Your maild "+mai+" is not corrrrect");
    return false;
    }
    }
    else
    {
    alert("Your maild "+mai+" is not correct");
    return false;
    }

    return true;
    }
    </script> <!-- Script by hscripts.com -->
    Here we have explained with a form
    a)Creating the form
    <form name="test" onSubmit="return checkMailId(test.mailf.value)">
    <input name=mailf type=text>
    <input type=submit value=test>
    </form>

    b)Copy the code in to your page.

    c)Things will work. The important portion is the onSubmit call in the form. "onSubmit = return checkMailId(test.mailf.value)". We call the method checkMaiId with the form fields value as the variable.

    d)If the mailid check is true form action willl take place, else alert will be done.
    hope that helps you, it took a quick google search to find


  3. #3
    Raman is offline Junior Member Array
    Join Date
    Feb 2006
    Answers
    15
    Quozty

    Thanks a lot for your kind help
    I learnt so much...

    Thanks again
    Good day to you
    Raman


    •    Sponsored Ads



Latest Article

Network Security Risk Assessment and Measurement

Read More...