ÿþf u n c t i o n   e m a i l C h e c k   ( e m a i l S t r )   {  
  
 / *   T h e   f o l l o w i n g   v a r i a b l e   t e l l s   t h e   r e s t   o f   t h e   f u n c t i o n   w h e t h e r   o r   n o t  
 t o   v e r i f y   t h a t   t h e   a d d r e s s   e n d s   i n   a   t w o - l e t t e r   c o u n t r y   o r   w e l l - k n o w n  
 T L D .     1   m e a n s   c h e c k   i t ,   0   m e a n s   d o n ' t .   * /  
  
 v a r   c h e c k T L D = 1 ;  
  
 / *   T h e   f o l l o w i n g   i s   t h e   l i s t   o f   k n o w n   T L D s   t h a t   a n   e - m a i l   a d d r e s s   m u s t   e n d   w i t h .   * /  
  
 v a r   k n o w n D o m s P a t = / ^ ( c o m | n e t | o r g | e d u | i n t | m i l | g o v | a r p a | b i z | a e r o | n a m e | c o o p | i n f o | p r o | m u s e u m ) $ / ;  
  
 / *   T h e   f o l l o w i n g   p a t t e r n   i s   u s e d   t o   c h e c k   i f   t h e   e n t e r e d   e - m a i l   a d d r e s s  
 f i t s   t h e   u s e r @ d o m a i n   f o r m a t .     I t   a l s o   i s   u s e d   t o   s e p a r a t e   t h e   u s e r n a m e  
 f r o m   t h e   d o m a i n .   * /  
  
 v a r   e m a i l P a t = / ^ ( . + ) @ ( . + ) $ / ;  
  
 / *   T h e   f o l l o w i n g   s t r i n g   r e p r e s e n t s   t h e   p a t t e r n   f o r   m a t c h i n g   a l l   s p e c i a l  
 c h a r a c t e r s .     W e   d o n ' t   w a n t   t o   a l l o w   s p e c i a l   c h a r a c t e r s   i n   t h e   a d d r e s s .    
 T h e s e   c h a r a c t e r s   i n c l u d e   (   )   <   >   @   ,   ;   :   \   "   .   [   ]   * /  
  
 v a r   s p e c i a l C h a r s = " \ \ ( \ \ ) > < @ , ; : \ \ \ \ \ \ \ " \ \ . \ \ [ \ \ ] " ;  
  
 / *   T h e   f o l l o w i n g   s t r i n g   r e p r e s e n t s   t h e   r a n g e   o f   c h a r a c t e r s   a l l o w e d   i n   a    
 u s e r n a m e   o r   d o m a i n n a m e .     I t   r e a l l y   s t a t e s   w h i c h   c h a r s   a r e n ' t   a l l o w e d . * /  
  
 v a r   v a l i d C h a r s = " \ [ ^ \ \ s "   +   s p e c i a l C h a r s   +   " \ ] " ;  
  
 / *   T h e   f o l l o w i n g   p a t t e r n   a p p l i e s   i f   t h e   " u s e r "   i s   a   q u o t e d   s t r i n g   ( i n  
 w h i c h   c a s e ,   t h e r e   a r e   n o   r u l e s   a b o u t   w h i c h   c h a r a c t e r s   a r e   a l l o w e d  
 a n d   w h i c h   a r e n ' t ;   a n y t h i n g   g o e s ) .     E . g .   " j i m i n y   c r i c k e t " @ d i s n e y . c o m  
 i s   a   l e g a l   e - m a i l   a d d r e s s .   * /  
  
 v a r   q u o t e d U s e r = " ( \ " [ ^ \ " ] * \ " ) " ;  
  
 / *   T h e   f o l l o w i n g   p a t t e r n   a p p l i e s   f o r   d o m a i n s   t h a t   a r e   I P   a d d r e s s e s ,  
 r a t h e r   t h a n   s y m b o l i c   n a m e s .     E . g .   j o e @ [ 1 2 3 . 1 2 4 . 2 3 3 . 4 ]   i s   a   l e g a l  
 e - m a i l   a d d r e s s .   N O T E :   T h e   s q u a r e   b r a c k e t s   a r e   r e q u i r e d .   * /  
  
 v a r   i p D o m a i n P a t = / ^ \ [ ( \ d { 1 , 3 } ) \ . ( \ d { 1 , 3 } ) \ . ( \ d { 1 , 3 } ) \ . ( \ d { 1 , 3 } ) \ ] $ / ;  
  
 / *   T h e   f o l l o w i n g   s t r i n g   r e p r e s e n t s   a n   a t o m   ( b a s i c a l l y   a   s e r i e s   o f   n o n - s p e c i a l   c h a r a c t e r s . )   * /  
  
 v a r   a t o m = v a l i d C h a r s   +   ' + ' ;  
  
 / *   T h e   f o l l o w i n g   s t r i n g   r e p r e s e n t s   o n e   w o r d   i n   t h e   t y p i c a l   u s e r n a m e .  
 F o r   e x a m p l e ,   i n   j o h n . d o e @ s o m e w h e r e . c o m ,   j o h n   a n d   d o e   a r e   w o r d s .  
 B a s i c a l l y ,   a   w o r d   i s   e i t h e r   a n   a t o m   o r   q u o t e d   s t r i n g .   * /  
  
 v a r   w o r d = " ( "   +   a t o m   +   " | "   +   q u o t e d U s e r   +   " ) " ;  
  
 / /   T h e   f o l l o w i n g   p a t t e r n   d e s c r i b e s   t h e   s t r u c t u r e   o f   t h e   u s e r  
  
 v a r   u s e r P a t = n e w   R e g E x p ( " ^ "   +   w o r d   +   " ( \ \ . "   +   w o r d   +   " ) * $ " ) ;  
  
 / *   T h e   f o l l o w i n g   p a t t e r n   d e s c r i b e s   t h e   s t r u c t u r e   o f   a   n o r m a l   s y m b o l i c  
 d o m a i n ,   a s   o p p o s e d   t o   i p D o m a i n P a t ,   s h o w n   a b o v e .   * /  
  
 v a r   d o m a i n P a t = n e w   R e g E x p ( " ^ "   +   a t o m   +   " ( \ \ . "   +   a t o m   + " ) * $ " ) ;  
  
 / *   F i n a l l y ,   l e t ' s   s t a r t   t r y i n g   t o   f i g u r e   o u t   i f   t h e   s u p p l i e d   a d d r e s s   i s   v a l i d .   * /  
  
 / *   B e g i n   w i t h   t h e   c o a r s e   p a t t e r n   t o   s i m p l y   b r e a k   u p   u s e r @ d o m a i n   i n t o  
 d i f f e r e n t   p i e c e s   t h a t   a r e   e a s y   t o   a n a l y z e .   * /  
  
 v a r   m a t c h A r r a y = e m a i l S t r . m a t c h ( e m a i l P a t ) ;  
  
 i f   ( m a t c h A r r a y = = n u l l )   {  
  
 / *   T o o   m a n y / f e w   @ ' s   o r   s o m e t h i n g ;   b a s i c a l l y ,   t h i s   a d d r e s s   d o e s n ' t  
 e v e n   f i t   t h e   g e n e r a l   m o u l d   o f   a   v a l i d   e - m a i l   a d d r e s s .   * /  
  
 a l e r t ( " ¤¿  E m a i l   µ¯½±¹  »¬¸¿Â" ) ;  
 r e t u r n   f a l s e ;  
 }  
 v a r   u s e r = m a t c h A r r a y [ 1 ] ;  
 v a r   d o m a i n = m a t c h A r r a y [ 2 ] ;  
  
 / /   S t a r t   b y   c h e c k i n g   t h a t   o n l y   b a s i c   A S C I I   c h a r a c t e r s   a r e   i n   t h e   s t r i n g s   ( 0 - 1 2 7 ) .  
  
 f o r   ( i = 0 ;   i < u s e r . l e n g t h ;   i + + )   {  
 i f   ( u s e r . c h a r C o d e A t ( i ) > 1 2 7 )   {  
 a l e r t ( " ›¬¸¿Â  u s e r n a m e ,   ÀµÁ¹­Çµ¹  ±º±Ä¬»»·»¿ÅÂ  Ç±Á±ºÄ®ÁµÂ" ) ;  
 r e t u r n   f a l s e ;  
       }  
 }  
 f o r   ( i = 0 ;   i < d o m a i n . l e n g t h ;   i + + )   {  
 i f   ( d o m a i n . c h a r C o d e A t ( i ) > 1 2 7 )   {  
 a l e r t ( " ›¬¸¿Â  d o m a i n ,     ÀµÁ¹­Çµ¹  ±º±Ä¬»»·»¿ÅÂ  Ç±Á±ºÄ®ÁµÂ" ) ;  
 r e t u r n   f a l s e ;  
       }  
 }  
  
 / /   S e e   i f   " u s e r "   i s   v a l i d    
  
 i f   ( u s e r . m a t c h ( u s e r P a t ) = = n u l l )   {  
  
 / /   u s e r   i s   n o t   v a l i d  
  
 a l e r t ( " ›¬¸¿Â  u s e r n a m e " ) ;  
 r e t u r n   f a l s e ;  
 }  
  
 / *   i f   t h e   e - m a i l   a d d r e s s   i s   a t   a n   I P   a d d r e s s   ( a s   o p p o s e d   t o   a   s y m b o l i c  
 h o s t   n a m e )   m a k e   s u r e   t h e   I P   a d d r e s s   i s   v a l i d .   * /  
  
 v a r   I P A r r a y = d o m a i n . m a t c h ( i p D o m a i n P a t ) ;  
 i f   ( I P A r r a y ! = n u l l )   {  
  
 / /   t h i s   i s   a n   I P   a d d r e s s  
  
 f o r   ( v a r   i = 1 ; i < = 4 ; i + + )   {  
 i f   ( I P A r r a y [ i ] > 2 5 5 )   {  
 a l e r t ( " —  ´¹µÍ¸Å½Ã·  I P   µ¯½±¹  »¬¸¿Â! " ) ;  
 r e t u r n   f a l s e ;  
       }  
 }  
 r e t u r n   t r u e ;  
 }  
  
 / /   D o m a i n   i s   s y m b o l i c   n a m e .     C h e c k   i f   i t ' s   v a l i d .  
    
 v a r   a t o m P a t = n e w   R e g E x p ( " ^ "   +   a t o m   +   " $ " ) ;  
 v a r   d o m A r r = d o m a i n . s p l i t ( " . " ) ;  
 v a r   l e n = d o m A r r . l e n g t h ;  
 f o r   ( i = 0 ; i < l e n ; i + + )   {  
 i f   ( d o m A r r [ i ] . s e a r c h ( a t o m P a t ) = = - 1 )   {  
 a l e r t ( " ›¬¸¿Â  d o m a i n . " ) ;  
 r e t u r n   f a l s e ;  
       }  
 }  
  
 / *   d o m a i n   n a m e   s e e m s   v a l i d ,   b u t   n o w   m a k e   s u r e   t h a t   i t   e n d s   i n   a  
 k n o w n   t o p - l e v e l   d o m a i n   ( l i k e   c o m ,   e d u ,   g o v )   o r   a   t w o - l e t t e r   w o r d ,  
 r e p r e s e n t i n g   c o u n t r y   ( u k ,   n l ) ,   a n d   t h a t   t h e r e ' s   a   h o s t n a m e   p r e c e d i n g    
 t h e   d o m a i n   o r   c o u n t r y .   * /  
  
 i f   ( c h e c k T L D   & &   d o m A r r [ d o m A r r . l e n g t h - 1 ] . l e n g t h ! = 2   & &    
 d o m A r r [ d o m A r r . l e n g t h - 1 ] . s e a r c h ( k n o w n D o m s P a t ) = = - 1 )   {  
 a l e r t ( " —  ´¹µÍ¸Å½Ã·  ÀÁ­Àµ¹  ½±  ÀµÁ¹­Çµ¹  ­½±  ÃÉÃÄÌ  d o m a i n   ®  ´Í¿  ³Á¬¼¼±Ä±  ³¹±  Ä·½  ÇÎÁ±" ) ;  
 r e t u r n   f a l s e ;  
 }  
  
 / /   M a k e   s u r e   t h e r e ' s   a   h o s t   n a m e   p r e c e d i n g   t h e   d o m a i n .  
  
 i f   ( l e n < 2 )   {  
 a l e r t ( " —  ´¹µÍ¸Å½Ã·  ´µ½  ÀµÁ¹­Çµ¹  h o s t n a m e " ) ;  
 r e t u r n   f a l s e ;  
 }  
  
 / /   I f   w e ' v e   g o t t e n   t h i s   f a r ,   e v e r y t h i n g ' s   v a l i d !  
 r e t u r n   t r u e ;  
 }  
  
 f u n c t i o n   g o o n ( ) 	 {  
 	 r e t u r n ;  
 }  
  
  
 f u n c t i o n   c h e c k a l l ( )  
 {  
 / / 	 s e t   t o d a y   v a l u e  
 	 v a r   d a t e O b j   =   n e w   D a t e  
 	 v a r   l m o n t h   =   d a t e O b j . g e t M o n t h ( )   + 1  
 	 v a r   d a t e   =   d a t e O b j . g e t D a t e ( )  
 	 v a r   f y e a r   =   d a t e O b j . g e t Y e a r ( )  
 	 i f   ( f y e a r   <   2 0 0 0 )   {  
 	 	 f y e a r   =   f y e a r   +   1 9 0 0  
 	 }  
 	 d o c u m e n t . f o r m s [ 0 ] . x d a t e . v a l u e =   d a t e   +   " / "   +   l m o n t h   +   " / "     +   f y e a r ;  
  
 	 i f     ( ( d o c u m e n t . f o r m s [ 0 ] . x l n a m e . v a l u e = = " " )   | |   ( d o c u m e n t . f o r m s [ 0 ] . x l n a m e . v a l u e = = " “Á¬ÈÄµ  Ä¿  µÀÎ½Å¼Ì  Ã±Â" ) )   	 {  
 	 	 a l e r t ( " ¤¿  µÀÎ½Å¼¿  ´µ½  ¼À¿Áµ¯  ½±'   ½±¹  ºµ½Ì" ) ;  
 	 	 d o c u m e n t . f o r m s [ 0 ] . x l n a m e . f o c u s ( ) ;  
 	 	 r e t u r n ;  
 	 }  
 	  
 	 i f     ( ( d o c u m e n t . f o r m s [ 0 ] . x f n a m e . v a l u e = = " " )   | |   ( d o c u m e n t . f o r m s [ 0 ] . x f n a m e . v a l u e = = " “Á¬ÈÄµ  Ä¿  Ì½¿¼¬  Ã±Â" ) )   	 {  
 	 	 a l e r t ( " ¤¿  Ì½¿¼±  ´µ½  ¼À¿Áµ¯  ½±'   ½±¹  ºµ½Ì" ) ;  
 	 	 d o c u m e n t . f o r m s [ 0 ] . x f n a m e . f o c u s ( ) ;  
 	 	 r e t u r n ;  
 	 }  
 	  
 	 i f     ( ( d o c u m e n t . f o r m s [ 0 ] . x f a t h e r . v a l u e = = " " )   | |   ( d o c u m e n t . f o r m s [ 0 ] . x f a t h e r . v a l u e = = " “Á¬ÈÄµ  Ä¿  À±ÄÁÎ½Å¼Ì  Ã±Â" ) ) 	 {  
 	 	 a l e r t ( " ¤¿  À±ÄÁÎ½Å¼¿  ´µ½  ¼À¿Áµ¯  ½±'   ½±¹  ºµ½Ì" ) ;  
 	 	 d o c u m e n t . f o r m s [ 0 ] . x f a t h e r . f o c u s ( ) ;  
 	 	 r e t u r n ;  
 	 }  
  
 	 i f     ( ( d o c u m e n t . f o r m s [ 0 ] . x a d d r . v a l u e = = " " )   | | 	 ( d o c u m e n t . f o r m s [ 0 ] . x a d d r . v a l u e = = " “Á¬ÈÄµ  Ä·½  ´¹µÍ¸Å½Ã®  Ã±Â" ) ) {  
 	 	 a l e r t ( " —  ”¹µÍ¸Å½Ã·  ´µ½  ¼À¿Áµ¯  ½±'   ½±¹  ºµ½®" ) ;  
 	 	 d o c u m e n t . f o r m s [ 0 ] . x a d d r . f o c u s ( ) ;  
 	 	 r e t u r n ;  
 	 }  
  
 	 i f     ( ( d o c u m e n t . f o r m s [ 0 ] . x c i t y . v a l u e = = " " )   | | 	 ( d o c u m e n t . f o r m s [ 0 ] . x c i t y . v a l u e = = " “Á¬ÈÄµ  Ä·½  ÀÌ»·  Ã±Â" ) ) {  
 	 	 a l e r t ( " —   Ì»·  ´µ½  ¼À¿Áµ¯  ½±'   ½±¹  ºµ½®" ) ;  
 	 	 d o c u m e n t . f o r m s [ 0 ] . x c i t y . f o c u s ( ) ;  
 	 	 r e t u r n ;  
 	 }  
  
 	 i f     ( ( d o c u m e n t . f o r m s [ 0 ] . x z i p . v a l u e = = " " )   | | 	 ( d o c u m e n t . f o r m s [ 0 ] . x z i p . v a l u e = = " 0 0 0 0 0 " ) ) {  
 	 	 a l e r t ( " Ÿ  Ä±ÇÅ´Á¿¼¹ºÌÂ  ºÎ´¹º±Â  ´µ½  ¼À¿Áµ¯  ½±'   ½±¹  ºµ½ÌÂ" ) ;  
 	 	 d o c u m e n t . f o r m s [ 0 ] . x z i p . f o c u s ( ) ;  
 	 	 r e t u r n ;  
 	 }  
 	  
 	 i f     ( ( d o c u m e n t . f o r m s [ 0 ] . x s t a t e . v a l u e = = " " )   | |   ( d o c u m e n t . f o r m s [ 0 ] . x s t a t e . v a l u e = = " “Á¬ÈÄµ  Ä·½  ÇÎÁ±  Ã±Â" ) ) 	 {  
 	 	 a l e r t ( " —  §ÎÁ±  ´µ½  ¼À¿Áµ¯  ½±'   ½±¹  ºµ½®" ) ;  
 	 	 d o c u m e n t . f o r m s [ 0 ] . x s t a t e . f o c u s ( ) ;  
 	 	 r e t u r n ;  
 	 }  
  
 	 i f     ( ( d o c u m e n t . f o r m s [ 0 ] . x p h o n e . v a l u e = = " " )   | |   ( d o c u m e n t . f o r m s [ 0 ] . x p h o n e . v a l u e = = " “Á¬ÈÄµ  Ä¿  Ä·»­ÆÉ½Ì  Ã±Â" ) ) 	 {  
 	 	 a l e r t ( " ¤¿  Ä·»­ÆÉ½¿  ´µ½  ¼À¿Áµ¯  ½±'   ½±¹  ºµ½Ì" ) ;  
 	 	 d o c u m e n t . f o r m s [ 0 ] . x p h o n e . f o c u s ( ) ;  
 	 	 r e t u r n ;  
 	 }  
  
  
 	 i f     ( ( d o c u m e n t . f o r m s [ 0 ] . x m a i l . v a l u e = = " " )   | | 	 ( d o c u m e n t . f o r m s [ 0 ] . x m a i l . v a l u e = = " “Á¬ÈÄµ  Ä¿  e m a i l   Ã±Â" ) ) {  
 	 	 a l e r t ( " T o   e - m a i l   ´µ½  ¼À¿Áµ¯  ½±  ½±¹  ºµ½Ì" ) ;  
 	 	 d o c u m e n t . f o r m s [ 0 ] . x m a i l . f o c u s ( ) ;  
 	 	 r e t u r n ;  
 	 }  
 	 e l s e 	 {  
 	 	 e m a i l S t r = d o c u m e n t . f o r m s [ 0 ] . x m a i l . v a l u e ;  
 	 	 i f   ( e m a i l C h e c k ( e m a i l S t r ) = = f a l s e   )   {  
 	 	 	 d o c u m e n t . f o r m s [ 0 ] . x m a i l . f o c u s ( ) ;  
 	 	 	 r e t u r n ;  
 	 	 }  
 	 } 	  
  
 	  
 	 d o c u m e n t . f o r m s [ 0 ] . s u b m i t ( ) ;  
 }  
  
  
 f u n c t i o n   c h e c k g r p a l l ( )  
 {  
 / / 	 s e t   t o d a y   v a l u e  
 	 v a r   d a t e O b j   =   n e w   D a t e  
 	 v a r   l m o n t h   =   d a t e O b j . g e t M o n t h ( )   + 1  
 	 v a r   d a t e   =   d a t e O b j . g e t D a t e ( )  
 	 v a r   f y e a r   =   d a t e O b j . g e t Y e a r ( )  
 	 i f   ( f y e a r   <   2 0 0 0 )   {  
 	 	 f y e a r   =   f y e a r   +   1 9 0 0  
 	 }  
 	 d o c u m e n t . f o r m s [ 0 ] . x d a t e . v a l u e =   d a t e   +   " / "   +   l m o n t h   +   " / "     +   f y e a r ;  
  
 	 i f     ( d o c u m e n t . f o r m s [ 0 ] . x g r p d e s c r . v a l u e = = " " )   	 {  
 	 	 a l e r t ( " —  ¿½¿¼±Ã¯±  ´µ½  ¼À¿Áµ¯  ½±'   ½±¹  ºµ½®" ) ;  
 	 	 d o c u m e n t . f o r m s [ 0 ] . x g r p d e s c r . f o c u s ( ) ;  
 	 	 r e t u r n ;  
 	 }  
 	  
 	 i f     ( d o c u m e n t . f o r m s [ 0 ] . x g r p t e x t . v a l u e = = " " )   	 {  
 	 	 a l e r t ( " —  ÀµÁ¹³Á±Æ®  ´µ½  ¼À¿Áµ¯  ½±'   ½±¹  ºµ½®" ) ;  
 	 	 d o c u m e n t . f o r m s [ 0 ] . x g r p t e x t . f o c u s ( ) ;  
 	 	 r e t u r n ;  
 	 }  
  
 	 d o c u m e n t . f o r m s [ 0 ] . s u b m i t ( ) ;  
 }  
  
 f u n c t i o n   m y t o d a y ( )  
 {  
 	 v a r   d a t e O b j   =   n e w   D a t e  
 	 v a r   l d a y   =   d a t e O b j . g e t D a y ( )  
 	 v a r   l m o n t h   =   d a t e O b j . g e t M o n t h ( )   +   1  
 	 v a r   d a t e   =   d a t e O b j . g e t D a t e ( )  
 	 v a r   f y e a r   =   d a t e O b j . g e t Y e a r ( )  
 	 i f   ( f y e a r   <   2 0 0 0 )   {  
 	 	 f y e a r   =   f y e a r   +   1 9 0 0  
 	 }  
 	 d o c u m e n t . w r i t e (   d a t e   +   " / "   +   l m o n t h   +   " / "     +   f y e a r )  
 	 r e t u r n ;  
 } 
