Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
This script validates the email and phone number fields entered by the user in a ServiceNow catalog item form.
It ensures that the email follows a valid format and the phone number is numeric with exactly 10 digits.


**Email Requirements:**
Must contain “@” and a valid domain (e.g., example.com).
No spaces or invalid characters allowed.

**Phone Number Requirements:**
Must contain exactly 10 digits.
Only numeric values allowed (no letters or special characters).
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
function onSubmit() {
// Get the field values
var email = g_form.getValue('email');
var phone = g_form.getValue('phone_number');

// Define validation patterns
var emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
var phonePattern = /^\d{10}$/;

// Validate email format
if (!emailPattern.test(email)) {
g_form.showFieldMsg('email', 'Please enter a valid email address (e.g., [email protected]).', 'error');
return false; // Prevent form submission
}

// Validate phone number
if (!phonePattern.test(phone)) {
g_form.showFieldMsg('phone_number', 'Phone number must be exactly 10 digits and contain only numbers.', 'error');
return false; // Prevent form submission
}

return true; // Allow form submission if all validations pass
}
Loading