Script Repository

Remove spaces from property value and validate it against regular expression

February 18, 2022

The script removes spaces from a property value, and then validates the result against a regular expression. If validation fails, the operation that triggered the script will be cancelled.

To use the script with Adaxes, create a business rule triggered before the operation you need. For example, if you want to validate a property of new users, create a business rule triggered before user creation. For details, see Validate/Modify User Input Using a Script.


  • $property - Specifies the LDAP display name of the property to validate.
  • $regex - Specifies the regular expression to check against.
Edit Remove
$property = "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($property)

if ([System.String]::IsNullOrEmpty($value))
    return # The property wasn't changed

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

# Validate property
if ($value -notmatch $regex)
    $Context.Cancel("The property must match the following regular expression: $regex") # TODO: modify me

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

Comments ( 0 )
No results found.
Leave a comment