Skip to content

isSHA256 — GTM Variable Template for Condition

VARIABLES › CONDITION
isSHA256 EXTENDED Condition

Checks if the provided value is SHA-256 hashed.



Examples

Valid SHA-256 hash
INPUT
Value To Check: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
OUTPUT
true
Invalid hash returns false
INPUT
Value To Check: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b85
OUTPUT
false

GTM Configuration

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
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
isSHA256()


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