@@ -217,6 +217,16 @@ const cloudFunctionUrl = "https://us-west1-ms-source-tracking-tool-dev.cloudfunc
217
217
}
218
218
} ;
219
219
220
+ const validateEmail = ( email ) => {
221
+ // Basic email validation regex that checks for:
222
+ // - At least one character before @
223
+ // - @ symbol
224
+ // - At least one character after @ (domain name)
225
+ // - At least one dot after @ with characters on both sides
226
+ const emailRegex = / ^ [ ^ \s @ ] + @ [ ^ \s @ ] + \. [ ^ \s @ ] + $ / ;
227
+ return emailRegex . test ( email ) ;
228
+ } ;
229
+
220
230
const handleEmailInputs = ( ) => {
221
231
const emailInputs = document . querySelectorAll (
222
232
'input[type="email"], input[name^="email"], input[name*="mail"]' ,
@@ -226,7 +236,8 @@ const cloudFunctionUrl = "https://us-west1-ms-source-tracking-tool-dev.cloudfunc
226
236
emailInput . addEventListener ( 'blur' , async ( ) => {
227
237
const email = emailInput . value . trim ( ) ;
228
238
229
- if ( email ) {
239
+ if ( email && validateEmail ( email ) ) {
240
+ // Only proceed if email is valid
230
241
const msSourceInfoCookie = getCookie ( COOKIE_NAME ) ;
231
242
232
243
if ( msSourceInfoCookie ) {
@@ -251,6 +262,8 @@ const cloudFunctionUrl = "https://us-west1-ms-source-tracking-tool-dev.cloudfunc
251
262
console . error ( 'Error processing email update:' , error ) ;
252
263
}
253
264
}
265
+ } else if ( email && ! validateEmail ( email ) ) {
266
+ console . log ( '❌ SourceLink: Invalid email format' ) ;
254
267
}
255
268
} ) ;
256
269
} ) ;
0 commit comments