isSHA256 β GTM Variable Template for Logic
When to Use This
Section titled βWhen to Use ThisβExamples
Section titled βExamplesβValid SHA-256 hash
INPUT
Value To Check: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
OUTPUT
true
Invalid hash returns false
INPUT
Value To Check: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b85
OUTPUT
false
Live Sandbox
Section titled βLive SandboxβThis is what you'll see when you open this variable in Google Tag Manager. Hover the icons for details.
isSHA256
Value To Check
πΎ The value to check.
Supported formats:
β All
Supported formats:
β All
Input Setup
Input Function (optional)
βοΈ Optional pre-processing function applied to the input before internal logic (e.g., convert object to string, normalize case). Internal transformations such as case handling will still apply afterward.
Result Handling
Output Function (optional)
βοΈ Optional function to apply to the result before returning it (e.g., str => str + ' β¬', val => val !== undefined for boolean conversion). Useful for chaining transformations on the output.
Value To Check string
π‘ Type any text to see the result update live
π― Using special value β click input to type instead
Test with:
Falsy
Truthy
π Result Handling β Chain Variables
Chain apply-mode variables to the output. Each variable receives the result of the previous one.
isSHA256()
Related Variables
Section titled βRelated VariablesβSame category: Logic
Under the Hood
Section titled βUnder the Hoodβπ View Implementation Code
/** * Checks if the value matches the SHA256 pattern. * * @param {any} data.src - The value to check. * @param {Function|string} [data.out] - Optional output handler: function to transform result or string with format. * * Direct-mode specific parameters: * @param {Function} [data.pre] - Optional pre-processor function to transform `src` before checking. * * @returns {boolean} True if the value matches the SHA256 pattern, false otherwise. * * @framework ggLowCodeGTMKit */const isSHA256 = function(value) { const pattern = "^[a-f0-9]{64}$"; return !!( typeof value === 'string' && value.toLowerCase().match(pattern) && value.toLowerCase().match(pattern)[0] === value.toLowerCase() );};const safeFunction = fn => typeof fn === 'function' ? fn : x => x;const out = safeFunction(data.out);// ===============================================================================// isSHA256 - Direct mode// ===============================================================================const applyCast = (castFn, value) => safeFunction(castFn)(value);const value = applyCast(data.pre, data.src);return out(isSHA256(value));// ===============================================================================// isSHA256() β Apply Mode// ===============================================================================/*return function(value) { return out(isSHA256(value));};*/π§ͺ View Test Scenarios (6 tests)
β
'[example] Valid SHA-256 hash'β
Valid SHA256 hash with uppercase - should return trueβ
'[example] Invalid hash returns false'β
Invalid too long - should return falseβ
Invalid contains invalid characters - should return falseβ
Not a string - should return false