Whatever message this page gives is out now! Go check it out!
IsValid(type, value)
isValid("range", value, min, max)
isValid("regex" or "regular_expression", value, pattern)Parameter | Description |
type | The valid format for the data; one of the following. For detailed information on validation algorithms, see Validating form data using hidden fields in the Developing ColdFusion Applications.
|
value | The value to test |
min | The minimum valid value; used only for range validation |
max | The maximum valid value; used only for range validation |
pattern | A JavaScript regular expression that the parameter must match; used only for regex or regular_expression validation. |
<cfif isDefined("form.saveSubmit")>
<cfif isValid("integer", form.UserID) and isValid("email", form.emailAddr)
and isValid("telephone", form.phoneNo)>
<cfoutput>
<!--- Application code to update the database goes here --->
<h3>The email address and phone number for user #Form.UserID#
have been added</h3>
</cfoutput>
<cfelse>
<H3>You must supply a valid User ID, phone number, and email address.</H2>
</cfif>
<cfelse>
</cfif>
<cfform action="#CGI.SCRIPT_NAME#">
User ID:<cfinput type="Text" name="UserID"><br>
Phone: <cfinput type="Text" name="phoneNo"><br>
email: <cfinput type="Text" name="emailAddr"><br>
<cfinput type="submit" name="saveSubmit" value="Save Data"><br>
</cfform><cfapplication name="hello" STRICTNUMBERVALIDATION="false" ><cfcomponent>
<cfscript>
{
this.STRICTNUMBERVALIDATION = false;
}
</cfscript>
</cfcomponent><cfscript>
// check if 50 is an integer
writeOutput(isValid("integer",50)) // Yes
// check if 3.14 is a numeric
writeOutput(isValid("numeric",3.14)) // Yes
// check if it is a valid url
writeOutput(isValid("URL","http://www.example.com")) // Yes
</cfscript><cfscript>
// Sample user registration data from different sources
userRegistrations = [
{"name": "John Doe", "email": "john.doe@company.com", "phone": "555-123-4567", "age": "28", "website": "https://johndoe.com", "password": "SecurePass123!", "zipCode": "12345"},
{"name": "Jane Smith", "email": "invalid-email-format", "phone": "555-CALL-NOW", "age": "thirty", "website": "not-a-valid-url", "password": "weak", "zipCode": "invalid"},
{"name": "Bob Johnson", "email": "bob@example.org", "phone": "1-800-555-1234", "age": "35", "website": "http://bobjohnson.net", "password": "StrongP@ssw0rd", "zipCode": "90210"},
{"name": "Alice Brown", "email": "alice.brown@domain.co.uk", "phone": "555.987.6543", "age": "42", "website": "", "password": "MySecure2024!", "zipCode": "10001"},
{"name": "Mike Wilson", "email": "mike@startup.io", "phone": "555-987-1234", "age": "31", "website": "https://startup.io", "password": "Innovation2024##", "zipCode": "94102"}
];
</cfscript>
<cfoutput>
<h2>📊 User Registration Validation Results</h2>
<cfloop array="#userRegistrations#" index="user">
<cfscript>
// Validate user registration fields using IsValid
nameValid = Len(Trim(user.name)) GTE 2;
emailValid = IsValid("email", user.email);
phoneValid = IsValid("telephone", user.phone);
ageValid = IsValid("integer", user.age) AND Val(user.age) GTE 18 AND Val(user.age) LE 120;
websiteValid = Len(Trim(user.website)) EQ 0 OR IsValid("url", user.website);
zipCodeValid = IsValid("regex", user.zipCode, "^[0-9]{5}(-[0-9]{4})?$");
// Password strength validation using regex pattern
strongPasswordRegex = "^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&##])[A-Za-z\d@$!%*?&##]{8,}$";
passwordValid = IsValid("regex", user.password, strongPasswordRegex);
// Calculate registration score
registrationScore = 0;
if (nameValid) registrationScore += 10;
if (emailValid) registrationScore += 25;
if (phoneValid) registrationScore += 20;
if (ageValid) registrationScore += 15;
if (websiteValid) registrationScore += 10;
if (passwordValid) registrationScore += 15;
if (zipCodeValid) registrationScore += 5;
// Determine registration quality
if (registrationScore GTE 90) {
registrationQuality = "Excellent";
qualityColor = "##28a745";
} else if (registrationScore GTE 75) {
registrationQuality = "Good";
qualityColor = "##17a2b8";
} else if (registrationScore GTE 50) {
registrationQuality = "Fair";
qualityColor = "##ffc107";
} else {
registrationQuality = "Poor";
qualityColor = "##dc3545";
}
// Count valid fields
validFieldCount = 0;
totalFields = 7;
if (nameValid) validFieldCount++;
if (emailValid) validFieldCount++;
if (phoneValid) validFieldCount++;
if (ageValid) validFieldCount++;
if (websiteValid) validFieldCount++;
if (passwordValid) validFieldCount++;
if (zipCodeValid) validFieldCount++;
</cfscript>
<div style="background: white; padding: 20px; margin: 15px 0; border-radius: 8px; border-left: 5px solid #qualityColor#; box-shadow: 0 2px 4px rgba(0,0,0,0.1);">
<div style="display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px; align-items: start;">
<!-- User Information -->
<div>
<h3 style="margin-top: 0; color: ##333;">User Registration</h3>
<p><strong>Name:</strong> #user.name#</p>
<p><strong>Email:</strong> #user.email#</p>
<p><strong>Phone:</strong> #user.phone#</p>
<p><strong>Age:</strong> #user.age#</p>
<p><strong>Website:</strong> #Len(user.website) GT 0 ? user.website : 'Not provided'#</p>
<p><strong>Zip Code:</strong> #user.zipCode#</p>
</div>
<!-- IsValid Results -->
<div>
<h4 style="margin-top: 0;">✅ Validation Results</h4>
<div style="background: ##f8f9fa; padding: 10px; border-radius: 3px; font-family: monospace; font-size: 0.85em;">
<p><strong>Name Valid:</strong> #nameValid ? 'Yes' : 'No'#</p>
<p><strong>Email Valid:</strong> #emailValid ? 'Yes' : 'No'#</p>
<p><strong>Phone Valid:</strong> #phoneValid ? 'Yes' : 'No'#</p>
<p><strong>Age Valid:</strong> #ageValid ? 'Yes' : 'No'#</p>
<cfif Len(user.website) GT 0>
<p><strong>Website Valid:</strong> #websiteValid ? 'Yes' : 'No'#</p>
<cfelse>
<p><strong>Website:</strong> Optional (not provided)</p>
</cfif>
<p><strong>Password Strong:</strong> #passwordValid ? 'Yes' : 'No'#</p>
<p><strong>Zip Code Valid:</strong> #zipCodeValid ? 'Yes' : 'No'#</p>
</div>
</div>
<!-- Registration Quality -->
<div>
<h4 style="margin-top: 0;">📊 Registration Quality</h4>
<p><strong>Valid Fields:</strong> #validFieldCount#/#totalFields#</p>
<p><strong>Score:</strong> #registrationScore#/100 points</p>
<p><strong>Quality:</strong> <span style="color: #qualityColor#; font-weight: bold;">#registrationQuality#</span></p>
<p><strong>Completion:</strong> #NumberFormat((validFieldCount/totalFields)*100, "0")#%</p>
</div>
</div>
<!-- Progress Bar -->
<div style="margin-top: 15px;">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 5px;">
<h5 style="margin: 0;">📈 Registration Progress</h5>
<span style="font-weight: bold; color: #qualityColor#;">#NumberFormat((registrationScore/100)*100, "0.0")#%</span>
</div>
<div style="background: ##e9ecef; height: 25px; border-radius: 12px; overflow: hidden; position: relative;">
<div style="background: #qualityColor#; height: 100%; width: #NumberFormat((registrationScore/100)*100, "0.0")#%; transition: width 0.3s ease;"></div>
<div style="position: absolute; top: 0; left: 0; right: 0; bottom: 0; display: flex; align-items: center; justify-content: center; color: white; font-weight: bold; font-size: 0.9em; text-shadow: 1px 1px 2px rgba(0,0,0,0.7);">
#validFieldCount# of #totalFields# fields valid
</div>
</div>
</div>
<!-- Field Validation Details -->
<div style="background: ##f8f9fa; padding: 15px; border-radius: 5px; margin-top: 15px;">
<h5 style="margin-top: 0;">🔍 Field Validation Details:</h5>
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 10px;">
<!-- Contact Information -->
<div style="background: white; padding: 10px; border-radius: 3px;">
<h6 style="margin-top: 0; color: ##17a2b8;">Contact Information</h6>
<p style="margin: 2px 0; color: #emailValid ? '##28a745' : '##dc3545'#;">
Email: #emailValid ? '✓ Valid format' : '✗ Invalid format'#
</p>
<p style="margin: 2px 0; color: #phoneValid ? '##28a745' : '##dc3545'#;">
Phone: #phoneValid ? '✓ Valid US format' : '✗ Invalid format'#
</p>
<p style="margin: 2px 0; color: #zipCodeValid ? '##28a745' : '##dc3545'#;">
Zip Code: #zipCodeValid ? '✓ Valid format' : '✗ Invalid format'#
</p>
</div>
<!-- Personal Information -->
<div style="background: white; padding: 10px; border-radius: 3px;">
<h6 style="margin-top: 0; color: ##28a745;">Personal Information</h6>
<p style="margin: 2px 0; color: #nameValid ? '##28a745' : '##dc3545'#;">
Name: #nameValid ? '✓ Valid length' : '✗ Too short'#
</p>
<p style="margin: 2px 0; color: #ageValid ? '##28a745' : '##dc3545'#;">
Age: #ageValid ? '✓ Valid age (18-120)' : '✗ Invalid age'#
</p>
<cfif Len(user.website) GT 0>
<p style="margin: 2px 0; color: #websiteValid ? '##28a745' : '##dc3545'#;">
Website: #websiteValid ? '✓ Valid URL' : '✗ Invalid URL'#
</p>
<cfelse>
<p style="margin: 2px 0; color: ##6c757d;">Website: Optional field</p>
</cfif>
</div>
<!-- Security -->
<div style="background: white; padding: 10px; border-radius: 3px;">
<h6 style="margin-top: 0; color: ##fd7e14;">Security</h6>
<p style="margin: 2px 0; color: #passwordValid ? '##28a745' : '##dc3545'#;">
Password: #passwordValid ? '✓ Strong password' : '✗ Weak password'#
</p>
<cfif NOT passwordValid>
<p style="margin: 2px 0; font-size: 0.8em; color: ##721c24;">
Requires: 8+ chars, upper, lower, number, special
</p>
</cfif>
</div>
</div>
</div>
<!-- Registration Actions -->
<div style="background: rgba(255,255,255,0.8); padding: 12px; border-radius: 5px; margin-top: 15px;">
<strong>📋 Registration Actions:</strong>
<cfif registrationQuality EQ "Excellent">
<br>• ✓ Approve registration immediately
<br>• ✓ Send welcome email to #user.email#
<br>• ✓ Set up user account with full privileges
<br>• ✓ Add to marketing automation system
<cfelseif registrationQuality EQ "Good">
<br>• ⚠ Request verification for weak fields
<br>• ✓ Allow registration with email confirmation
<br>• ⚠ Send data quality improvement suggestions
<br>• ✓ Set up basic user account
<cfelseif registrationQuality EQ "Fair">
<br>• ⚠ Require field corrections before approval
<br>• ⚠ Send validation error messages to user
<br>• ⚠ Offer assistance with data entry
<br>• ⚠ Hold registration pending improvements
<cfelse>
<br>• ✗ Reject registration - too many errors
<br>• ✗ Display comprehensive error messages
<br>• ✗ Offer customer service contact information
<br>• ✗ Log failed registration attempt
</cfif>
</div>
</div>
</cfloop>
<h2>📈 Registration Analytics Dashboard</h2>
<div style="background: ##f8f9fa; padding: 20px; border-radius: 8px; margin: 15px 0;">
<cfscript>
// Calculate registration statistics
totalRegistrations = ArrayLen(userRegistrations);
successfulRegistrations = 0;
averageScore = 0;
totalScore = 0;
emailSuccessRate = 0;
phoneSuccessRate = 0;
passwordSuccessRate = 0;
overallValidCount = 0;
for (user in userRegistrations) {
local.emailValid = IsValid("email", user.email);
local.phoneValid = IsValid("telephone", user.phone);
local.ageValid = IsValid("integer", user.age) AND Val(user.age) GTE 18 AND Val(user.age) LE 120;
local.passwordValid = IsValid("regex", user.password, "^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&##])[A-Za-z\d@$!%*?&##]{8,}$");
local.zipValid = IsValid("regex", user.zipCode, "^[0-9]{5}(-[0-9]{4})?$");
local.websiteValid = Len(Trim(user.website)) EQ 0 OR IsValid("url", user.website);
local.nameValid = Len(Trim(user.name)) GTE 2;
local.score = 0;
if (local.nameValid) local.score += 10;
if (local.emailValid) local.score += 25;
if (local.phoneValid) local.score += 20;
if (local.ageValid) local.score += 15;
if (local.websiteValid) local.score += 10;
if (local.passwordValid) local.score += 15;
if (local.zipValid) local.score += 5;
totalScore += local.score;
if (local.score GTE 75) successfulRegistrations++;
if (local.emailValid) emailSuccessRate++;
if (local.phoneValid) phoneSuccessRate++;
if (local.passwordValid) passwordSuccessRate++;
}
averageScore = totalScore / totalRegistrations;
emailSuccessRate = (emailSuccessRate / totalRegistrations) * 100;
phoneSuccessRate = (phoneSuccessRate / totalRegistrations) * 100;
passwordSuccessRate = (passwordSuccessRate / totalRegistrations) * 100;
successRate = (successfulRegistrations / totalRegistrations) * 100;
</cfscript>
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 20px;">
<div style="background: white; padding: 15px; border-radius: 5px; text-align: center;">
<h3 style="margin: 0; color: ##28a745;">#successfulRegistrations#</h3>
<p style="margin: 5px 0 0 0;">Successful Registrations</p>
</div>
<div style="background: white; padding: 15px; border-radius: 5px; text-align: center;">
<h3 style="margin: 0; color: ##17a2b8;">#NumberFormat(averageScore, "0.0")#</h3>
<p style="margin: 5px 0 0 0;">Average Quality Score</p>
</div>
<div style="background: white; padding: 15px; border-radius: 5px; text-align: center;">
<h3 style="margin: 0; color: ##ffc107;">#NumberFormat(successRate, "0.0")#%</h3>
<p style="margin: 5px 0 0 0;">Success Rate</p>
</div>
<div style="background: white; padding: 15px; border-radius: 5px; text-align: center;">
<h3 style="margin: 0; color: ##6f42c1;">#totalRegistrations#</h3>
<p style="margin: 5px 0 0 0;">Total Registrations</p>
</div>
</div>
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 20px; margin-top: 20px;">
<div style="background: white; padding: 15px; border-radius: 5px; text-align: center;">
<h3 style="margin: 0; color: ##28a745;">#NumberFormat(emailSuccessRate, "0")#%</h3>
<p style="margin: 5px 0 0 0;">Valid Emails</p>
</div>
<div style="background: white; padding: 15px; border-radius: 5px; text-align: center;">
<h3 style="margin: 0; color: ##17a2b8;">#NumberFormat(phoneSuccessRate, "0")#%</h3>
<p style="margin: 5px 0 0 0;">Valid Phone Numbers</p>
</div>
<div style="background: white; padding: 15px; border-radius: 5px; text-align: center;">
<h3 style="margin: 0; color: ##fd7e14;">#NumberFormat(passwordSuccessRate, "0")#%</h3>
<p style="margin: 5px 0 0 0;">Strong Passwords</p>
</div>
</div>
</div>
</cfoutput><cfscript>
// Sample API requests from various sources
apiRequests = [
{"endpoint": "/api/orders", "userId": "12345", "amount": "299.99", "currency": "USD", "itemCount": "3", "priority": "high", "apiKey": "abc123xyz789", "timestamp": "1698765432"},
{"endpoint": "/api/payments", "userId": "invalid_user", "amount": "not_a_number", "currency": "INVALID", "itemCount": "-5", "priority": "urgent", "apiKey": "invalid", "timestamp": "invalid"},
{"endpoint": "/api/orders", "userId": "67890", "amount": "1500.00", "currency": "EUR", "itemCount": "1", "priority": "normal", "apiKey": "def456uvw901", "timestamp": "1698765500"},
{"endpoint": "/api/refunds", "userId": "11111", "amount": "0.99", "currency": "GBP", "itemCount": "10", "priority": "low", "apiKey": "ghi789rst234", "timestamp": "1698765600"},
{"endpoint": "/api/orders", "userId": "22222", "amount": "5000.00", "currency": "CAD", "itemCount": "25", "priority": "high", "apiKey": "jkl012mno567", "timestamp": "1698765700"}
];
</cfscript>
<cfoutput>
<h2>📊 API Request Validation Results</h2>
<cfloop array="#apiRequests#" index="request">
<cfscript>
// Generate unique request ID
requestId = "REQ" & DateFormat(Now(), "yyyymmdd") & TimeFormat(Now(), "HHmmss") & RandRange(100, 999);
// Validate API parameters using IsValid
userIdValid = IsValid("integer", request.userId) AND Val(request.userId) GT 0;
amountValid = IsValid("numeric", request.amount) AND Val(request.amount) GTE 0;
itemCountValid = IsValid("integer", request.itemCount) AND Val(request.itemCount) GT 0 AND Val(request.itemCount) LE 100;
timestampValid = IsValid("integer", request.timestamp) AND Len(request.timestamp) EQ 10;
// Validate business rules
validCurrencies = "USD,EUR,GBP,CAD,AUD,JPY";
currencyValid = ListFind(validCurrencies, UCase(request.currency)) GT 0;
validPriorities = "low,normal,high,urgent";
priorityValid = ListFind(validPriorities, LCase(request.priority)) GT 0;
validEndpoints = "/api/orders,/api/payments,/api/refunds";
endpointValid = ListFind(validEndpoints, request.endpoint) GT 0;
// API Key validation (basic format check)
apiKeyValid = IsValid("regex", request.apiKey, "^[a-zA-Z0-9]{12}$");
// Calculate security score
securityScore = 100;
parametersPassed = 0;
totalParameters = 8;
if (userIdValid) parametersPassed++; else securityScore -= 15;
if (amountValid) parametersPassed++; else securityScore -= 20;
if (itemCountValid) parametersPassed++; else securityScore -= 10;
if (timestampValid) parametersPassed++; else securityScore -= 10;
if (currencyValid) parametersPassed++; else securityScore -= 10;
if (priorityValid) parametersPassed++; else securityScore -= 5;
if (endpointValid) parametersPassed++; else securityScore -= 15;
if (apiKeyValid) parametersPassed++; else securityScore -= 15;
// Additional security checks
if (amountValid AND Val(request.amount) GT 10000) {
securityScore -= 5; // Large transaction warning
}
if (itemCountValid AND Val(request.itemCount) GT 50) {
securityScore -= 3; // High volume warning
}
// Determine security level
if (securityScore GTE 95) {
securityLevel = "High Security";
securityColor = "##28a745";
requestStatus = "APPROVED";
} else if (securityScore GTE 80) {
securityLevel = "Medium Security";
securityColor = "##17a2b8";
requestStatus = "APPROVED";
} else if (securityScore GTE 60) {
securityLevel = "Low Security";
securityColor = "##ffc107";
requestStatus = "REVIEW REQUIRED";
} else {
securityLevel = "Security Risk";
securityColor = "##dc3545";
requestStatus = "REJECTED";
}
</cfscript>
<div style="background: white; padding: 20px; margin: 15px 0; border-radius: 8px; border-left: 5px solid #securityColor#; box-shadow: 0 2px 4px rgba(0,0,0,0.1);">
<div style="display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px; align-items: start;">
<!-- Request Details -->
<div>
<h3 style="margin-top: 0; color: ##333;">API Request</h3>
<p><strong>Request ID:</strong> #requestId#</p>
<p><strong>Endpoint:</strong> #request.endpoint#</p>
<p><strong>User ID:</strong> #request.userId#</p>
<p><strong>Amount:</strong> $#request.amount# #request.currency#</p>
<p><strong>Items:</strong> #request.itemCount#</p>
<p><strong>Priority:</strong> #request.priority#</p>
</div>
<!-- IsValid Results -->
<div>
<h4 style="margin-top: 0;">✅ Parameter Validation</h4>
<div style="background: ##f8f9fa; padding: 10px; border-radius: 3px; font-family: monospace; font-size: 0.85em;">
<p><strong>User ID:</strong> #userIdValid ? 'Valid ✓' : 'Invalid ✗'#</p>
<p><strong>Amount:</strong> #amountValid ? 'Valid ✓' : 'Invalid ✗'#</p>
<p><strong>Item Count:</strong> #itemCountValid ? 'Valid ✓' : 'Invalid ✗'#</p>
<p><strong>Timestamp:</strong> #timestampValid ? 'Valid ✓' : 'Invalid ✗'#</p>
<p><strong>Currency:</strong> #currencyValid ? 'Valid ✓' : 'Invalid ✗'#</p>
<p><strong>Priority:</strong> #priorityValid ? 'Valid ✓' : 'Invalid ✗'#</p>
<p><strong>Endpoint:</strong> #endpointValid ? 'Valid ✓' : 'Invalid ✗'#</p>
<p><strong>API Key:</strong> #apiKeyValid ? 'Valid ✓' : 'Invalid ✗'#</p>
</div>
</div>
<!-- Security Assessment -->
<div>
<h4 style="margin-top: 0;">🔒 Security Assessment</h4>
<p><strong>Parameters Passed:</strong> #parametersPassed#/#totalParameters#</p>
<p><strong>Security Score:</strong> #securityScore#/100</p>
<p><strong>Security Level:</strong> <span style="color: #securityColor#; font-weight: bold;">#securityLevel#</span></p>
<p><strong>Request Status:</strong> <span style="color: #securityColor#; font-weight: bold;">#requestStatus#</span></p>
</div>
</div>
<!-- Security Progress Bar -->
<div style="margin-top: 15px;">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 5px;">
<h5 style="margin: 0;">🛡️ Security Score</h5>
<span style="font-weight: bold; color: #securityColor#;">#securityScore#/100</span>
</div>
<div style="background: ##e9ecef; height: 25px; border-radius: 12px; overflow: hidden; position: relative;">
<div style="background: #securityColor#; height: 100%; width: #securityScore#%; transition: width 0.3s ease;"></div>
<div style="position: absolute; top: 0; left: 0; right: 0; bottom: 0; display: flex; align-items: center; justify-content: center; color: white; font-weight: bold; font-size: 0.9em; text-shadow: 1px 1px 2px rgba(0,0,0,0.7);">
#parametersPassed# of #totalParameters# parameters valid
</div>
</div>
</div>
<!-- Validation Details -->
<div style="background: ##f8f9fa; padding: 15px; border-radius: 5px; margin-top: 15px;">
<h5 style="margin-top: 0;">🔍 Validation Details:</h5>
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 10px;">
<!-- Data Type Validation -->
<div style="background: white; padding: 10px; border-radius: 3px;">
<h6 style="margin-top: 0; color: ##17a2b8;">Data Type Validation</h6>
<p style="margin: 2px 0; color: #userIdValid ? '##28a745' : '##dc3545'#;">
User ID (Integer): #userIdValid ? '✓ Valid positive integer' : '✗ Must be positive integer'#
</p>
<p style="margin: 2px 0; color: #amountValid ? '##28a745' : '##dc3545'#;">
Amount (Numeric): #amountValid ? '✓ Valid positive number' : '✗ Must be positive number'#
</p>
<p style="margin: 2px 0; color: #itemCountValid ? '##28a745' : '##dc3545'#;">
Item Count: #itemCountValid ? '✓ Valid range (1-100)' : '✗ Must be 1-100'#
</p>
<p style="margin: 2px 0; color: #timestampValid ? '##28a745' : '##dc3545'#;">
Timestamp: #timestampValid ? '✓ Valid Unix timestamp' : '✗ Invalid timestamp'#
</p>
</div>
<!-- Business Rule Validation -->
<div style="background: white; padding: 10px; border-radius: 3px;">
<h6 style="margin-top: 0; color: ##28a745;">Business Rules</h6>
<p style="margin: 2px 0; color: #currencyValid ? '##28a745' : '##dc3545'#;">
Currency: #currencyValid ? '✓ Supported currency' : '✗ Unsupported currency'#
</p>
<p style="margin: 2px 0; color: #priorityValid ? '##28a745' : '##dc3545'#;">
Priority: #priorityValid ? '✓ Valid priority level' : '✗ Invalid priority'#
</p>
<p style="margin: 2px 0; color: #endpointValid ? '##28a745' : '##dc3545'#;">
Endpoint: #endpointValid ? '✓ Authorized endpoint' : '✗ Unauthorized endpoint'#
</p>
</div>
<!-- Security Validation -->
<div style="background: white; padding: 10px; border-radius: 3px;">
<h6 style="margin-top: 0; color: ##fd7e14;">Security Checks</h6>
<p style="margin: 2px 0; color: #apiKeyValid ? '##28a745' : '##dc3545'#;">
API Key: #apiKeyValid ? '✓ Valid format' : '✗ Invalid format'#
</p>
<cfif amountValid AND Val(request.amount) GT 10000>
<p style="margin: 2px 0; color: ##ffc107;">⚠ Large transaction detected</p>
</cfif>
<cfif itemCountValid AND Val(request.itemCount) GT 50>
<p style="margin: 2px 0; color: ##ffc107;">⚠ High volume transaction</p>
</cfif>
</div>
</div>
</div>
<!-- API Response Actions -->
<div style="background: rgba(255,255,255,0.8); padding: 12px; border-radius: 5px; margin-top: 15px;">
<strong>📋 API Response Actions:</strong>
<cfif requestStatus EQ "APPROVED">
<br>• ✓ Process request normally
<br>• ✓ Log successful validation
<br>• ✓ Return 200 OK with response data
<cfif securityScore LT 95>
<br>• ⚠ Monitor for unusual patterns
</cfif>
<cfelseif requestStatus EQ "REVIEW REQUIRED">
<br>• ⚠ Flag for manual review
<br>• ⚠ Return 202 Accepted (pending review)
<br>• ⚠ Send notification to security team
<br>• ⚠ Log security concern for analysis
<cfelse>
<br>• ✗ Reject request immediately
<br>• ✗ Return 400 Bad Request with error details
<br>• ✗ Log security violation attempt
<br>• ✗ Consider rate limiting for this source
</cfif>
</div>
</div>
</cfloop>
<h2>📈 API Security Dashboard</h2>
<div style="background: ##f8f9fa; padding: 20px; border-radius: 8px; margin: 15px 0;">
<cfscript>
// Calculate API security statistics
totalRequests = ArrayLen(apiRequests);
approvedRequests = 0;
reviewRequests = 0;
rejectedRequests = 0;
averageSecurityScore = 0;
totalSecurityScore = 0;
highSecurityCount = 0;
mediumSecurityCount = 0;
lowSecurityCount = 0;
riskCount = 0;
for (request in apiRequests) {
local.userIdValid = IsValid("integer", request.userId) AND Val(request.userId) GT 0;
local.amountValid = IsValid("numeric", request.amount) AND Val(request.amount) GTE 0;
local.itemCountValid = IsValid("integer", request.itemCount) AND Val(request.itemCount) GT 0 AND Val(request.itemCount) LE 100;
local.timestampValid = IsValid("integer", request.timestamp) AND Len(request.timestamp) EQ 10;
local.currencyValid = ListFind("USD,EUR,GBP,CAD,AUD,JPY", UCase(request.currency)) GT 0;
local.priorityValid = ListFind("low,normal,high,urgent", LCase(request.priority)) GT 0;
local.endpointValid = ListFind("/api/orders,/api/payments,/api/refunds", request.endpoint) GT 0;
local.apiKeyValid = IsValid("regex", request.apiKey, "^[a-zA-Z0-9]{12}$");
local.score = 100;
if (NOT local.userIdValid) local.score -= 15;
if (NOT local.amountValid) local.score -= 20;
if (NOT local.itemCountValid) local.score -= 10;
if (NOT local.timestampValid) local.score -= 10;
if (NOT local.currencyValid) local.score -= 10;
if (NOT local.priorityValid) local.score -= 5;
if (NOT local.endpointValid) local.score -= 15;
if (NOT local.apiKeyValid) local.score -= 15;
if (local.amountValid AND Val(request.amount) GT 10000) local.score -= 5;
if (local.itemCountValid AND Val(request.itemCount) GT 50) local.score -= 3;
totalSecurityScore += local.score;
if (local.score GTE 95) {
approvedRequests++;
highSecurityCount++;
} else if (local.score GTE 80) {
approvedRequests++;
mediumSecurityCount++;
} else if (local.score GTE 60) {
reviewRequests++;
lowSecurityCount++;
} else {
rejectedRequests++;
riskCount++;
}
}
averageSecurityScore = totalSecurityScore / totalRequests;
approvalRate = (approvedRequests / totalRequests) * 100;
</cfscript>
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 20px;">
<div style="background: white; padding: 15px; border-radius: 5px; text-align: center;">
<h3 style="margin: 0; color: ##28a745;">#approvedRequests#</h3>
<p style="margin: 5px 0 0 0;">Approved Requests</p>
</div>
<div style="background: white; padding: 15px; border-radius: 5px; text-align: center;">
<h3 style="margin: 0; color: ##ffc107;">#reviewRequests#</h3>
<p style="margin: 5px 0 0 0;">Review Required</p>
</div>
<div style="background: white; padding: 15px; border-radius: 5px; text-align: center;">
<h3 style="margin: 0; color: ##dc3545;">#rejectedRequests#</h3>
<p style="margin: 5px 0 0 0;">Rejected Requests</p>
</div>
<div style="background: white; padding: 15px; border-radius: 5px; text-align: center;">
<h3 style="margin: 0; color: ##17a2b8;">#NumberFormat(approvalRate, "0.0")#%</h3>
<p style="margin: 5px 0 0 0;">Approval Rate</p>
</div>
</div>
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 20px; margin-top: 20px;">
<div style="background: white; padding: 15px; border-radius: 5px; text-align: center;">
<h3 style="margin: 0; color: ##28a745;">#highSecurityCount#</h3>
<p style="margin: 5px 0 0 0;">High Security</p>
</div>
<div style="background: white; padding: 15px; border-radius: 5px; text-align: center;">
<h3 style="margin: 0; color: ##17a2b8;">#mediumSecurityCount#</h3>
<p style="margin: 5px 0 0 0;">Medium Security</p>
</div>
<div style="background: white; padding: 15px; border-radius: 5px; text-align: center;">
<h3 style="margin: 0; color: ##ffc107;">#lowSecurityCount#</h3>
<p style="margin: 5px 0 0 0;">Low Security</p>
</div>
<div style="background: white; padding: 15px; border-radius: 5px; text-align: center;">
<h3 style="margin: 0; color: ##dc3545;">#riskCount#</h3>
<p style="margin: 5px 0 0 0;">Security Risks</p>
</div>
</div>
<div style="margin-top: 20px; text-align: center;">
<div style="background: white; padding: 15px; border-radius: 5px;">
<h3 style="margin: 0; color: ##6f42c1;">#NumberFormat(averageSecurityScore, "0.0")#</h3>
<p style="margin: 5px 0 0 0;">Average Security Score</p>
</div>
</div>
</div>
</cfoutput><cfscript>
// Sample customer data requiring validation
customerData = [
{"type": "Email", "value": "john.doe@company.com", "required": true},
{"type": "Email", "value": "jane.smith@invalid-domain", "required": true},
{"type": "Phone", "value": "555-123-4567", "required": true},
{"type": "Phone", "value": "1-800-SUPPORT", "required": false},
{"type": "Account ID", "value": "ACC-2024-001234", "required": true},
{"type": "Reference", "value": "REF##INV-2024-5678", "required": true},
{"type": "SSN", "value": "123-45-6789", "required": true},
{"type": "Credit Card", "value": "4532-1234-5678-9012", "required": false}
];
</cfscript>
<cfoutput>
<h2>📊 Data Validation Results</h2>
<cfloop array="#customerData#" index="dataItem">
<cfscript>
// Validate different data types using Find function
dataValue = dataItem.value;
dataType = dataItem.type;
isValid = false;
validationMessages = [];
errorMessages = [];
// Email validation
if (dataType EQ "Email") {
atPos = Find("@", dataValue);
dotPos = Find(".", dataValue);
if (atPos GT 1 AND dotPos GT atPos AND dotPos LT Len(dataValue)) {
isValid = true;
ArrayAppend(validationMessages, "Valid email structure detected");
// Check for common invalid patterns
if (Find("invalid", dataValue) GT 0) {
isValid = false;
ArrayAppend(errorMessages, "Domain contains 'invalid' keyword");
}
} else {
ArrayAppend(errorMessages, "Missing required @ symbol or domain extension");
}
}
// Phone number validation
else if (dataType EQ "Phone") {
dashPos = Find("-", dataValue);
digitCount = 0;
// Count digits
for (i = 1; i LTE Len(dataValue); i++) {
if (IsNumeric(Mid(dataValue, i, 1))) {
digitCount++;
}
}
if (dashPos GT 0 AND digitCount GTE 10) {
if (Find("555-", dataValue) GT 0 AND digitCount EQ 10) {
isValid = true;
ArrayAppend(validationMessages, "Valid US phone number format");
} else if (Find("1-800", dataValue) GT 0) {
isValid = true;
ArrayAppend(validationMessages, "Valid toll-free number");
} else {
ArrayAppend(errorMessages, "Unrecognized phone format");
}
} else {
ArrayAppend(errorMessages, "Missing hyphens or insufficient digits");
}
}
// Account ID validation
else if (dataType EQ "Account ID") {
accPos = Find("ACC-", dataValue);
if (accPos EQ 1 AND Len(dataValue) GTE 10) {
isValid = true;
ArrayAppend(validationMessages, "Valid account ID format");
} else {
ArrayAppend(errorMessages, "Must start with ACC- and be at least 10 characters");
}
}
// Reference ID validation
else if (dataType EQ "Reference") {
refPos = Find("REF", dataValue);
hashPos = Find("##", dataValue);
if (refPos EQ 1 AND hashPos EQ 4) {
isValid = true;
ArrayAppend(validationMessages, "Valid reference ID format");
} else {
ArrayAppend(errorMessages, "Must start with REF## pattern");
}
}
// SSN validation
else if (dataType EQ "SSN") {
firstDash = Find("-", dataValue);
secondDash = Find("-", dataValue, firstDash + 1);
if (firstDash EQ 4 AND secondDash EQ 7 AND Len(dataValue) EQ 11) {
isValid = true;
ArrayAppend(validationMessages, "Valid SSN format (XXX-XX-XXXX)");
} else {
ArrayAppend(errorMessages, "Must follow XXX-XX-XXXX format");
}
}
// Credit Card validation
else if (dataType EQ "Credit Card") {
dashCount = 0;
dashPos = 1;
while (dashPos GT 0) {
dashPos = Find("-", dataValue, dashPos + 1);
if (dashPos GT 0) dashCount++;
}
if (dashCount EQ 3 AND Len(dataValue) EQ 19) {
isValid = true;
ArrayAppend(validationMessages, "Valid credit card format (XXXX-XXXX-XXXX-XXXX)");
} else {
ArrayAppend(errorMessages, "Must follow XXXX-XXXX-XXXX-XXXX format");
}
}
// Determine validation status color
statusColor = isValid ? "##28a745" : "##dc3545";
typeColor = "##17a2b8";
</cfscript>
<div style="background: white; padding: 20px; margin: 15px 0; border-radius: 8px; border-left: 5px solid #statusColor#; box-shadow: 0 2px 4px rgba(0,0,0,0.1);">
<div style="display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px; align-items: start;">
<!-- Data Item Info -->
<div>
<h3 style="margin-top: 0; color: ##333;">Data Validation</h3>
<p><strong>Type:</strong> <span style="color: #typeColor#; font-weight: bold;">#dataType#</span></p>
<p><strong>Value:</strong> #dataValue#</p>
<p><strong>Required:</strong> #dataItem.required ? 'Yes' : 'No'#</p>
<p><strong>Status:</strong> <span style="color: #statusColor#; font-weight: bold;">#isValid ? 'Valid' : 'Invalid'#</span></p>
</div>
<!-- Find Function Analysis -->
<div>
<h4 style="margin-top: 0;">🔍 Pattern Detection</h4>
<div style="background: ##f8f9fa; padding: 10px; border-radius: 3px; font-family: monospace; font-size: 0.85em;">
<cfif dataType EQ "Email">
<p><strong>@ symbol:</strong> position #Find("@", dataValue)#</p>
<p><strong>. symbol:</strong> position #Find(".", dataValue)#</p>
<cfelseif dataType EQ "Phone">
<p><strong>- symbol:</strong> position #Find("-", dataValue)#</p>
<cfif Find("1-800", dataValue) GT 0>
<p><strong>1-800:</strong> position #Find("1-800", dataValue)#</p>
</cfif>
<cfelseif dataType EQ "Account ID">
<p><strong>ACC- prefix:</strong> position #Find("ACC-", dataValue)#</p>
<cfelseif dataType EQ "Reference">
<p><strong>REF prefix:</strong> position #Find("REF", dataValue)#</p>
<p><strong>## symbol:</strong> position #Find("##", dataValue)#</p>
<cfelseif dataType EQ "SSN">
<p><strong>First -:</strong> position #Find("-", dataValue)#</p>
<p><strong>Second -:</strong> position #Find("-", dataValue, 5)#</p>
<cfelseif dataType EQ "Credit Card">
<p><strong>Dash count:</strong> #Len(dataValue) - Len(Replace(dataValue, "-", "", "ALL"))#</p>
</cfif>
</div>
</div>
<!-- Validation Results -->
<div>
<h4 style="margin-top: 0;">✅ Validation Details</h4>
<cfif ArrayLen(validationMessages) GT 0>
<div style="color: ##28a745;">
<cfloop array="#validationMessages#" index="message">
<p style="margin: 2px 0; font-size: 0.9em;">✓ #message#</p>
</cfloop>
</div>
</cfif>
<cfif ArrayLen(errorMessages) GT 0>
<div style="color: ##dc3545;">
<cfloop array="#errorMessages#" index="error">
<p style="margin: 2px 0; font-size: 0.9em;">✗ #error#</p>
</cfloop>
</div>
</cfif>
</div>
</div>
<!-- Compliance and Security Notes -->
<cfif dataType EQ "SSN" OR dataType EQ "Credit Card">
<div style="background: ##fff3cd; padding: 12px; border-radius: 5px; margin-top: 15px;">
<h6 style="margin-top: 0;">🔒 Security & Compliance Notes:</h6>
<cfif dataType EQ "SSN">
<p>• SSN data requires PII protection and GDPR compliance</p>
<p>• Encrypt during storage and transmission</p>
<p>• Log all access for audit purposes</p>
<cfelseif dataType EQ "Credit Card">
<p>• Credit card data requires PCI DSS compliance</p>
<p>• Never store full card numbers in plain text</p>
<p>• Use tokenization for payment processing</p>
</cfif>
</div>
</cfif>
</div>
</cfloop>
<h2>📈 Data Quality Dashboard</h2>
<div style="background: ##f8f9fa; padding: 20px; border-radius: 8px; margin: 15px 0;">
<cfscript>
// Calculate validation statistics
totalRecords = ArrayLen(customerData);
validRecords = 0;
invalidRecords = 0;
requiredRecords = 0;
validRequiredRecords = 0;
emailCount = 0;
phoneCount = 0;
accountCount = 0;
piiCount = 0;
for (dataItem in customerData) {
// Re-validate for statistics
local.isValid = false;
dataValue = dataItem.value;
dataType = dataItem.type;
if (dataType EQ "Email") {
emailCount++;
local.atPos = Find("@", dataValue);
local.dotPos = Find(".", dataValue);
if (local.atPos GT 1 AND local.dotPos GT local.atPos AND Find("invalid", dataValue) EQ 0) {
local.isValid = true;
}
} else if (dataType EQ "Phone") {
phoneCount++;
if (Find("-", dataValue) GT 0 AND (Find("555-", dataValue) GT 0 OR Find("1-800", dataValue) GT 0)) {
local.isValid = true;
}
} else if (dataType EQ "Account ID") {
accountCount++;
if (Find("ACC-", dataValue) EQ 1) {
local.isValid = true;
}
} else if (dataType EQ "Reference") {
if (Find("REF", dataValue) EQ 1 AND Find("##", dataValue) EQ 4) {
local.isValid = true;
}
} else if (dataType EQ "SSN" OR dataType EQ "Credit Card") {
piiCount++;
if (dataType EQ "SSN" AND Find("-", dataValue) EQ 4) {
local.isValid = true;
} else if (dataType EQ "Credit Card" AND Len(dataValue) EQ 19) {
local.isValid = true;
}
}
if (local.isValid) validRecords++;
else invalidRecords++;
if (dataItem.required) {
requiredRecords++;
if (local.isValid) validRequiredRecords++;
}
}
validationRate = (validRecords / totalRecords) * 100;
requiredValidationRate = requiredRecords GT 0 ? (validRequiredRecords / requiredRecords) * 100 : 0;
</cfscript>
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 20px;">
<div style="background: white; padding: 15px; border-radius: 5px; text-align: center;">
<h3 style="margin: 0; color: ##28a745;">#validRecords#</h3>
<p style="margin: 5px 0 0 0;">Valid Records</p>
</div>
<div style="background: white; padding: 15px; border-radius: 5px; text-align: center;">
<h3 style="margin: 0; color: ##dc3545;">#invalidRecords#</h3>
<p style="margin: 5px 0 0 0;">Invalid Records</p>
</div>
<div style="background: white; padding: 15px; border-radius: 5px; text-align: center;">
<h3 style="margin: 0; color: ##17a2b8;">#NumberFormat(validationRate, "0.0")#%</h3>
<p style="margin: 5px 0 0 0;">Overall Validation Rate</p>
</div>
<div style="background: white; padding: 15px; border-radius: 5px; text-align: center;">
<h3 style="margin: 0; color: ##fd7e14;">#NumberFormat(requiredValidationRate, "0.0")#%</h3>
<p style="margin: 5px 0 0 0;">Required Fields Valid</p>
</div>
</div>
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 20px; margin-top: 20px;">
<div style="background: white; padding: 15px; border-radius: 5px; text-align: center;">
<h3 style="margin: 0; color: ##6f42c1;">#emailCount#</h3>
<p style="margin: 5px 0 0 0;">Email Addresses</p>
</div>
<div style="background: white; padding: 15px; border-radius: 5px; text-align: center;">
<h3 style="margin: 0; color: ##28a745;">#phoneCount#</h3>
<p style="margin: 5px 0 0 0;">Phone Numbers</p>
</div>
<div style="background: white; padding: 15px; border-radius: 5px; text-align: center;">
<h3 style="margin: 0; color: ##17a2b8;">#accountCount#</h3>
<p style="margin: 5px 0 0 0;">Account IDs</p>
</div>
<div style="background: white; padding: 15px; border-radius: 5px; text-align: center;">
<h3 style="margin: 0; color: ##dc3545;">#piiCount#</h3>
<p style="margin: 5px 0 0 0;">PII Records</p>
</div>
</div>
</div>
</cfoutput>