Script repository

Remove spaces from property value and validate it against regular expression

Updated on: Jan 18, 2026, Views: 4476

Property validation, Provisioning

The script remove spaces from property value and validate it against regular expression. If the validation fails, the operation is cancelled. To execute the script, create a business rule triggering Before creating a user or Before updating a user.

Parameters

  • $propertyName - the name of the property to validate.
  • $regex - the regular expression to validate property value against.
$propertyName = "mail" # TODO: modify me
$regex = "^[a-zA-Z0-9_.%%-+]+@([a-zA-Z0-9_-]+.)+[a-zA-Z0-9_-]+$" # TODO: modify me

# Get property value
$value = $Context.GetModifiedPropertyValue($propertyName)

if ([System.String]::IsNullOrEmpty($value))
{
    return
}

# Remove spaces
$value = $value.Replace(" ", "")

# Validate against regular expression
if ($value -notmatch $regex)
{
    $Context.Cancel("Value of property $propertyName does not match regular expression: $regex") # TODO: modify me
}

# Update property value.
$Context.SetModifiedPropertyValue($propertyName, $value)

Comments 0

You must be signed in to comment.

    Got questions?

    Support Questions & Answers

    We use cookies to improve your experience.
    By your continued use of this site you accept such use.
    For more details please see our privacy policy and cookies policy.