ÿþ/ /   * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *  
 / /   * * *   S c r i p t   B y   J o h n   R o m a n o   R a f o l   |   M a r c h   1 3 ,   2 0 0 1   * * *  
 / /   * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *  
  
  
 f u n c t i o n   i s D e c i m a l ( s t r V a l u e )  
 {  
 	 i f   ( i s N a N ( p a r s e F l o a t ( s t r V a l u e ) ) )  
 	 	 r e t u r n ( f a l s e )  
 	 e l s e  
 	 	 r e t u r n ( t r u e ) ;  
 }  
  
 f u n c t i o n   i s I n t e g e r ( s t r V a l u e )  
 {  
 	 i f   ( i s N a N ( p a r s e I n t ( s t r V a l u e ) ) )  
 	 	 r e t u r n ( f a l s e )  
 	 e l s e  
 	 	 r e t u r n ( t r u e ) ;  
 }  
  
  
 f u n c t i o n   i s V a l i d E x t ( s t r V a l u e )  
 {  
 	 i f   ( s t r V a l u e . l e n g t h   <   3 )  
 	 	 r e t u r n ( f a l s e )  
 	 e l s e   i f   ( i s N a N ( p a r s e I n t ( s t r V a l u e ) ) )  
 	 	 r e t u r n ( f a l s e )  
 	 e l s e  
 	 	 r e t u r n ( t r u e ) ;  
 }  
  
 f u n c t i o n   i s T e l e p h o n e ( s t r V a l u e )  
 {  
 	 v a r   i n t L e n ,   i n t C t r ,   i n t A s c C o d e ;  
  
 	 i n t L e n = ( s t r V a l u e . l e n g t h ) ;  
 	 f o r   ( i n t C t r = 0 ;   i n t L e n   >   i n t C t r ;   i n t C t r + + )    
 	 {  
 	 	 i n t A s c C o d e   =   s t r V a l u e . c h a r C o d e A t ( i n t C t r ) ;  
 	 	 i f   (   ! ( ( ( i n t A s c C o d e   > =   4 8 )   & &   ( i n t A s c C o d e   < =   5 7 ) )     | |  
 	 	               ( ( i n t A s c C o d e   = =   4 5 )   | |   ( i n t A s c C o d e   = =   3 2 ) ) )   ) 	 / / * * *   4 5   i s   a   h y p e n   w h i l e   3 2   i s   a   s p a c e .   4 8 - 5 7   i s   t h e   0 - 9   n u m b e r s  
 	 	 { 	  
 	 	 	 r e t u r n ( f a l s e ) ;  
 	 	 }  
 	 }  
  
 	 i f   ( i n t L e n   <   6 )  
 	 	 r e t u r n ( f a l s e ) ;  
 	 e l s e  
 	 	 r e t u r n ( t r u e ) ;  
 } 	  
  
 f u n c t i o n   i s A l p h a N u m e r i c ( s t r V a l u e )  
 {  
 	 v a r   i n t C t r ;  
 	 i n t L e n   =   s t r V a l u e . l e n g t h ;  
 	  
 	 f o r   ( i n t C t r = 0 ;   i n t L e n   >   i n t C t r ;   i n t C t r + + )    
 	 {  
 	 	 i n t A s c C o d e   =   s t r V a l u e . c h a r C o d e A t ( i n t C t r ) ;  
 	 	  
 	 	 i f   (   ! ( ( ( i n t A s c C o d e   > =   4 8 )   & &   ( i n t A s c C o d e   < =   5 7 ) )         | |   / / * * *   4 8 - 5 7     a r e   t h e   0 - 9   n u m b e r s  
 	 	               ( ( i n t A s c C o d e   > =   6 5 )   & &   ( i n t A s c C o d e   < =   9 0 ) )         | |   / / * * *   6 5 - 9 0   a r e   t h e   A - Z   c a p i t a l   l e t t e r s 	 	  
 	 	               ( ( i n t A s c C o d e   > =   9 7 )   & &   ( i n t A s c C o d e   < =   1 2 2 ) ) )   )       / / * * *   9 7 - 1 2 2   a r e   t h e   a - z   s m a l l   l e t t e r s 	  
 	 	 { 	  
 	 	 	 r e t u r n ( f a l s e ) ;  
 	 	 }  
 	 }  
 	 r e t u r n ( t r u e ) ;  
 }  
  
 f u n c t i o n   e m p t y _ s t r i n g ( s t r V a l u e )  
 {  
 	 v a r   c t r ,   i n t _ l e n g t h ,   e m p t y   =   t r u e ;  
 	 i n t _ l e n g t h   =   s t r V a l u e . l e n g t h ;  
  
 	 f o r   ( c t r = 0 ; c t r < i n t _ l e n g t h ; c t r + + )  
 	 {  
 	 	 i f   ( s t r V a l u e . c h a r A t ( c t r )   ! =   " "   & &   s t r V a l u e . c h a r A t ( c t r )   ! =   "   "   & &   s t r V a l u e . c h a r C o d e A t ( c t r )   ! =   1 3     & &   s t r V a l u e . c h a r C o d e A t ( c t r )   ! =   1 0 )  
 	 	 	 e m p t y   =   f a l s e ;  
 	 }  
  
 	 i f   ( ( s t r V a l u e . l e n g t h   = =   0 )   | |   ( e m p t y ) )  
 	 	 r e t u r n ( t r u e ) ;  
  
 	 r e t u r n ( f a l s e ) ;  
 }  
  
 f u n c t i o n   V a l i d a t e F o r m ( o b j F o r m )  
 {  
 	 v a r   s t r V a l i d a t i o n M s g   =   " " ;  
 	 v a r   i   =   o b j F o r m . t a g s ( " I N P U T " ) ;  
 	 v a r   i 2   =   o b j F o r m . t a g s ( " T E X T A R E A " ) ; 	  
 	 v a r   c t r = 0 ,   c t r 2 = 0 ,   i n t I n d e x = 0 ;  
 	 v a r   b o o l S u b m i t   =   f a l s e ;  
  
 	 f o r   ( c t r = 0 ;   c t r   <   i . l e n g t h ;   c t r + + )  
 	 {  
 	 	 i f   ( ( i . i t e m ( c t r ) . t y p e   = =   " t e x t "   | |   i . i t e m ( c t r ) . t y p e   = =   " p a s s w o r d " )   & &   ! ( i . i t e m ( c t r ) . d i s a b l e d )   & &   i . i t e m ( c t r ) . p r o p R e q u i r e d   ! =   " n o " )  
 	 	 {  
 	 	 	 i f   (   ( e m p t y _ s t r i n g ( i . i t e m ( c t r ) . v a l u e ) )   | |   ( i . i t e m ( c t r ) . p r o p E x t F i e l d   = =   " y e s "   & &   ! i s V a l i d E x t ( i . i t e m ( c t r ) . v a l u e ) )   | |   ( i . i t e m ( c t r ) . p r o p T e l F i e l d   = =   " y e s "   & &   ! i s T e l e p h o n e ( i . i t e m ( c t r ) . v a l u e ) )   )  
 	 	 	 	 i n t I n d e x   + + ;  
  
 	 	 	 s t r V a l i d a t i o n M s g   =   s t r V a l i d a t i o n M s g   +   ( ( e m p t y _ s t r i n g ( i . i t e m ( c t r ) . v a l u e )   | |   ( i . i t e m ( c t r ) . p r o p E x t F i e l d   = =   " y e s "   & &   ! i s V a l i d E x t ( i . i t e m ( c t r ) . v a l u e ) )   | |   ( i . i t e m ( c t r ) . p r o p T e l F i e l d   = =   " y e s "   & &   ! i s T e l e p h o n e ( i . i t e m ( c t r ) . v a l u e ) )   )   ?   i n t I n d e x . t o S t r i n g ( )   +   " .   "   +   i . i t e m ( c t r ) . n a m e . r e p l a c e ( / _ / g , "   " )   +   " \ n "   :   " " ) ;  
 	 	 }  
 	 }  
 	  
 	  
 	 f o r   ( c t r 2 = 0 ;   c t r 2   <   i 2 . l e n g t h ;   c t r 2 + + )  
 	 {  
 	 	 i f   ( ! ( i 2 . i t e m ( c t r 2 ) . d i s a b l e d )   & &   i 2 . i t e m ( c t r 2 ) . p r o p R e q u i r e d   ! =   " n o " )  
 	 	 {  
 	 	 	 i f   (   e m p t y _ s t r i n g ( i 2 . i t e m ( c t r 2 ) . v a l u e )   )  
 	 	 	 	 i n t I n d e x   + + ;  
  
 	 	 	 s t r V a l i d a t i o n M s g   =   s t r V a l i d a t i o n M s g   +   ( e m p t y _ s t r i n g ( i 2 . i t e m ( c t r 2 ) . v a l u e   )   ?   i n t I n d e x . t o S t r i n g ( )   +   " .   "   +   i 2 . i t e m ( c t r 2 ) . n a m e . r e p l a c e ( / _ / g , "   " )   +   " \ n "   :   " " ) ;  
 	 	 }  
 	 } 	  
  
 	 i f   ( s t r V a l i d a t i o n M s g = = " " )  
 	 {  
 	 	 r e t u r n   ( t r u e ) ;   / / * * *   V a l i d a t i o n   C r i t e r i o n s   P a s s e d ,   g o   f o r t h   a n d   p r o c e s s   t h e   f o r m   * * *  
 	 }  
 	 e l s e  
 	 {  
 	 	 a l e r t (   " N h ïn g   m åc   s a u   â y   c h éa   t h ô n g   t i n   k h ô n g   h ãp   l Ç  h o ·c   c h °a   °ãc   i Án   v à o .   :   \ n \ n "   +   s t r V a l i d a t i o n M s g ) ;   / / * * *   O o p s ,   I   t h i n k   t h e r e ' s   a n   e r r o r   * * *  
 	 	 r e t u r n   ( f a l s e )  
 	 } 	  
 } 	  
  
  
 f u n c t i o n   I n V a l i d E m a i l ( e m a i l S t r )  
 {  
 	 v a r   c h e c k T L D = 1 ;  
 	 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 ) $ / ;  
 	 v a r   e m a i l P a t = / ^ ( . + ) @ ( . + ) $ / ;  
 	 v a r   s p e c i a l C h a r s = " \ \ ( \ \ ) > < @ , ; : \ \ \ \ \ \ \ " \ \ . \ \ [ \ \ ] " ;  
 	 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   +   " \ ] " ;  
 	 v a r   q u o t e d U s e r = " ( \ " [ ^ \ " ] * \ " ) " ;  
 	 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 } ) \ ] $ / ;  
 	 v a r   a t o m = v a l i d C h a r s   +   ' + ' ;  
 	 v a r   w o r d = " ( "   +   a t o m   +   " | "   +   q u o t e d 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   +   " ) * $ " ) ;  
 	 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   + " ) * $ " ) ;  
 	 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 )  
 	       {  
 	         a l e r t ( " E m a i l   a d d r e s s   s e e m s   i n c o r r e c t   ( c h e c k   @   a n d   . ' s ) " ) ;  
 	         r e t u r n   t r u 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 ] ;  
  
 	 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 ( " T h i s   u s e r n a m e   c o n t a i n s   i n v a l i d   c h a r a c t e r s . " ) ;  
 	 	 r e t u r n   t r u 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 ( " T h s   d o m a i n   n a m e   c o n t a i n s   i n v a l i d   c h a r a c t e r s . " ) ;  
 	 	   r e t u r n   t r u e ;  
 	 	 }  
 	         }  
  
 	 i f   ( u s e r . m a t c h ( u s e r P a t ) = = n u l l )  
 	       {  
 	         a l e r t ( " T h e   u s e r n a m e   d o e s n ' t   s e e m   t o   b e   v a l i d . " ) ;  
 	         r e t u r n   t r u e ;  
 	       }  
  
 	 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 )  
 	       {  
 	         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 ( " D e s t i n a t i o n   I P   a d d r e s s   i s   i n v a l i d ! " ) ;  
 	 	           r e t u r n   t r u e ;  
 	 	         }  
 	 	 }  
 	         r e t u r n   f a l s e ;  
 	       }  
  
 	 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 ( " T h e   d o m a i n   n a m e   d o e s   n o t   s e e m   t o   b e   v a l i d . " ) ;  
 	 	   r e t u r n   t r u e ;  
 	 	 }  
 	         }  
  
 	 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 ( " T h e   a d d r e s s   m u s t   e n d   i n   a   w e l l - k n o w n   d o m a i n   o r   t w o   l e t t e r   "   +   " c o u n t r y . " ) ;  
 	         r e t u r n   t r u e ;  
 	       }  
  
 	 i f   ( l e n < 2 )  
 	       {  
 	         a l e r t ( " T h i s   a d d r e s s   i s   m i s s i n g   a   h o s t n a m e ! " ) ;  
 	         r e t u r n   t r u e ;  
 	       }  
  
 	 r e t u r n   f a l s e ;  
  
 } 
