Skip to content

Commit eb08bfc

Browse files
cbarley10claude
andcommitted
Fix phone validation to accept formatted phone numbers
Strip common formatting characters (spaces, parentheses, hyphens, dots) before validating phone numbers. This allows formats like (508) 999-9999, 508-999-9999, and 508.999.9999 to be accepted. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 0f2374e commit eb08bfc

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed

public/klaviyo_hotel_tracking_cloudbeds.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,10 @@
235235
return emailRegex.test(email);
236236
}
237237
function isValidPhone(phone) {
238+
if (!phone) return false;
239+
const cleanPhone = phone.replace(/[\s\(\)\-\.]/g, "");
238240
const phoneRegex = /^\+?[0-9]{10,15}$/;
239-
return phoneRegex.test(phone);
241+
return phoneRegex.test(cleanPhone);
240242
}
241243

242244
// src/shared/debugConfig.js

public/klaviyo_hotel_tracking_guesty.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
return emailRegex.test(email);
1313
}
1414
function isValidPhone(phone) {
15+
if (!phone) return false;
16+
const cleanPhone = phone.replace(/[\s\(\)\-\.]/g, "");
1517
const phoneRegex = /^\+?[0-9]{10,15}$/;
16-
return phoneRegex.test(phone);
18+
return phoneRegex.test(cleanPhone);
1719
}
1820

1921
// src/shared/debugConfig.js

public/klaviyo_hotel_tracking_mews.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,10 @@
337337
return emailRegex.test(email);
338338
}
339339
function isValidPhone(phone) {
340+
if (!phone) return false;
341+
const cleanPhone = phone.replace(/[\s\(\)\-\.]/g, "");
340342
const phoneRegex = /^\+?[0-9]{10,15}$/;
341-
return phoneRegex.test(phone);
343+
return phoneRegex.test(cleanPhone);
342344
}
343345

344346
// src/shared/debugConfig.js

src/shared/validationUtils.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,15 @@ export function isValidEmail(email) {
77
return emailRegex.test(email);
88
}
99

10-
// Phone validation
10+
// Phone validation - strips common formatting characters before validation
1111
export function isValidPhone(phone) {
12+
if (!phone) return false;
13+
14+
// Strip common formatting characters (spaces, parentheses, hyphens, dots)
15+
// Keep + if it's at the beginning
16+
const cleanPhone = phone.replace(/[\s\(\)\-\.]/g, '');
17+
18+
// Must have 10-15 digits, optionally starting with +
1219
const phoneRegex = /^\+?[0-9]{10,15}$/;
13-
return phoneRegex.test(phone);
20+
return phoneRegex.test(cleanPhone);
1421
}

0 commit comments

Comments
 (0)