Skip to content

Commit 638ca0c

Browse files
authored
script.js
1 parent 9d0508b commit 638ca0c

File tree

1 file changed

+23
-0
lines changed
  • Client-Side Components/Catalog Client Script/Email & PhNo Validation

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
function onSubmit() {
2+
// Get the field values
3+
var email = g_form.getValue('email');
4+
var phone = g_form.getValue('phone_number');
5+
6+
// Define validation patterns
7+
var emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
8+
var phonePattern = /^\d{10}$/;
9+
10+
// Validate email format
11+
if (!emailPattern.test(email)) {
12+
g_form.showFieldMsg('email', 'Please enter a valid email address (e.g., user@example.com).', 'error');
13+
return false; // Prevent form submission
14+
}
15+
16+
// Validate phone number
17+
if (!phonePattern.test(phone)) {
18+
g_form.showFieldMsg('phone_number', 'Phone number must be exactly 10 digits and contain only numbers.', 'error');
19+
return false; // Prevent form submission
20+
}
21+
22+
return true; // Allow form submission if all validations pass
23+
}

0 commit comments

Comments
 (0)