File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -119,8 +119,25 @@ const Contact: React.FC = () => {
119119 { type : 'ai' , text : '>>> [AiTor]: Neural connection active. Ready to assist.' }
120120 ] ) ;
121121
122+ const [ formErrors , setFormErrors ] = useState < Record < string , string > > ( { } ) ;
123+
124+ const emailRegex = / ^ [ ^ \s @ ] + @ [ ^ \s @ ] + \. [ ^ \s @ ] + $ / ;
125+
126+ const validateForm = ( ) : boolean => {
127+ const errors : Record < string , string > = { } ;
128+ if ( ! formData . name . trim ( ) || formData . name . trim ( ) . length < 2 ) errors . name = 'Name must be at least 2 characters' ;
129+ if ( formData . name . length > 100 ) errors . name = 'Name must be less than 100 characters' ;
130+ if ( ! emailRegex . test ( formData . email ) ) errors . email = 'Please enter a valid email address' ;
131+ if ( formData . subject . length > 200 ) errors . subject = 'Subject must be less than 200 characters' ;
132+ if ( ! formData . message . trim ( ) || formData . message . trim ( ) . length < 10 ) errors . message = 'Message must be at least 10 characters' ;
133+ if ( formData . message . length > 2000 ) errors . message = 'Message must be less than 2000 characters' ;
134+ setFormErrors ( errors ) ;
135+ return Object . keys ( errors ) . length === 0 ;
136+ } ;
137+
122138 const handleFormSubmit = ( e : React . FormEvent ) => {
123139 e . preventDefault ( ) ;
140+ if ( ! validateForm ( ) ) return ;
124141 setIsSubmitting ( true ) ;
125142 const mailtoLink = `mailto:alien69flow@proton.me?subject=${ encodeURIComponent ( formData . subject ) } &body=${ encodeURIComponent ( `FROM: ${ formData . name } \nEMAIL: ${ formData . email } \n\n${ formData . message } ` ) } ` ;
126143 window . location . href = mailtoLink ;
You can’t perform that action at this time.
0 commit comments