PageSourceSearch

https://www.kleen-ritecorp.com/scripts/validate.postalcoderegexlookup.js

js kleen-ritecorp.com collected 2026-10-04 00:02:08 UTC 1,605 bytes, 46 lines download raw bytes

1(function($, configuration) {
2	// Load the postal code regex map via AJAX. Until it's loaded, all client-side validation will pass.
3	var postalCodeRegexMap = {};
4	$.getJSON(configuration.postalCodeRegexMapUrl).done(function(map) {
5		postalCodeRegexMap = map;
6	});
7
8	// Register the postal code regex lookup validator with JQuery Validator and Unobtrusive Validation.
9	$.validator.unobtrusive.adapters.addSingleVal(
10		'postalcoderegexlookup',
11		'lookupkeyname'
12	);
13	$.validator.addMethod('postalcoderegexlookup', function(
14		value,
15		element,
16		lookupKeyName
17	) {
18		// Extract the prefix from the name of field being validated
19		var prefix = element.name.substr(0, element.name.lastIndexOf('.') + 1);
20
21		// Apply the prefix to the name of the lookup key to get the lookup key element name
22		var fullLookupKeyName = lookupKeyName;
23		if (fullLookupKeyName.indexOf('*.') === 0) {
24			fullLookupKeyName = fullLookupKeyName.replace('*.', prefix);
25		}
26
27		// Get the value from the lookup key element
28		var escapedLookupKeyName = fullLookupKeyName.replace(
29			/([!"#$%&'()*+,./:;<=>?@@\[\\\]^`{|}~])/g,
30			'\\$1'
31		);
32		var lookupKeyValue = $(element.form)
33			.find(':input')
34			.filter("[name='" + escapedLookupKeyName + "']")
35			.first()
36			.val();
37
38		// If we couldn't find the lookup key or if the key doesn't exist in the map, treat as valid
39		if (!lookupKeyValue || !postalCodeRegexMap[lookupKeyValue]) {
40			return true;
41		}
42
43		// Test the value against the regex for the lookup key value
44		return RegExp(postalCodeRegexMap[lookupKeyValue]).test(value);
45	});
46})(adnsf$, window.postalCodeRegexConfiguration);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.