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,17 @@
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}

// Regular expression for email validation
var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;

// Test the email against the pattern
if (!emailPattern.test(newValue)) {
g_form.showFieldMsg('email_field_name', 'Invalid email format. Example: user@example.com', 'error');
g_form.hideFieldMsg('email_field_name', true); // Clear info messages
} else {
g_form.hideFieldMsg('email_field_name'); // Clear error message
g_form.showFieldMsg('email_field_name', 'Valid email address', 'info');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
function onSubmit() {
// Get the email field value
var email = g_form.getValue('email_field_name'); // Replace 'email_field_name' with your actual field name

// Check if email field has a value
if (email) {
// Regular expression for email validation
var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;

// Test the email against the pattern
if (!emailPattern.test(email)) {
g_form.addErrorMessage('Please enter a valid email address');
g_form.showFieldMsg('email_field_name', 'Invalid email format. Example: user@example.com', 'error');
return false; // Prevent form submission
}
}

return true; // Allow form submission
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# ServiceNow Email Validation Catalog Client Script

## Overview
Client-side validation script for ServiceNow catalog items to ensure proper email format in user input fields.

## Features
- Real-time email format validation
- Form submission prevention for invalid emails
- User-friendly error messages
- Standard email pattern validation

## Implementation
1. Navigate to **Service Catalog > Catalog Client Scripts**
2. Create new script and select catalog item
3. Choose script type: **onSubmit** or **onChange**
4. Replace `email_field_name` with your field variable name
5. Save and activate

## Validation Rules
- Required format: `user@domain.com`
- Accepts: letters, numbers, dots, underscores, hyphens
- Minimum 2-character domain extension

## Script Types
- **onSubmit**: Validates before form submission
- **onChange**: Real-time validation as user types

## Usage
Best practice: Use both scripts for comprehensive validation and better user experience.
Loading