Quick Search:
CODE
Oracle PL/SQL Code Library
JOBS
Find Or Post Oracle Jobs
FORUM
Oracle Discussion & Chat
 JavaScript: Ultimate domain name validator Jump to:  
Category: >> JavaScript >> Ultimate domain name validator Bookmark and Share

<< lastnext >>

Snippet Name: Ultimate domain name validator

Description: This will validate nearly any domain name correctly.

Comment: (none)

Language: JAVASCRIPT
Highlight Mode: JAVASCRIPT
Last Modified: February 28th, 2009

 
FUNCTION checkDomain(nname)
{
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 = nname;
VAR val = TRUE;
 
VAR dot = mai.lastIndexOf(".");
VAR dname = mai.substring(0,dot);
VAR ext = mai.substring(dot,mai.length);
//alert(ext);
 
IF(dot>2 && dot<57)
{
     FOR(VAR i=0; i<arr.length; i++)
     {
       IF(ext == arr[i])
       {
           val = TRUE;
          BREAK;
       }     
       ELSE
       {
           val = FALSE;
       }
     }
     IF(val == FALSE)
     {
             ALERT("The domain extension "+ext+" is incorrect or unknown.");
           RETURN FALSE;
     }
     ELSE
     {
          FOR(VAR j=0; j<dname.length; j++)
          {
            VAR dh = dname.charAt(j);
            VAR hh = dh.charCodeAt(0);
            IF((hh > 47 && hh<59) || (hh > 64 && hh<91) || (hh > 96 && hh<123) || hh==45 || hh==46)
            {
                IF((j==0 || j==dname.length-1) && hh == 45)     
                  {
                        ALERT("The domain name cannot begin or end with '-'");
                     RETURN FALSE;
                 }
            }
          ELSE     {
                  ALERT("Your domain name cannot contain any special characters.");
                RETURN FALSE;
            }
          }
     }
}
ELSE
{
 ALERT("The domain name entered is either too short or too long");
 RETURN FALSE;
}     
 
RETURN TRUE;
}


Free
Oracle Magazine
Subscriptions
and Oracle White Papers


SQL University.net courses meet the most demanding needs of the business world for advanced education in a cost-effective manner. SQL University.net courses are available immediately for IT professionals and can be taken without disruption of your workplace schedule or processes.

Compared to traditional travel-based training, SQL University.net saves time and valuable corporate resources, allowing companies to do more with less. That's our mission, and that's what we deliver.

Click here to find out more
 
Home      :      Code Library      :      Sponsors      :      Privacy      :      Terms of Use      :      Contact Us 92 users online    © 2009 psoug.org

PSOUG LOGIN
Username: 
Password: 
Forgot your password?