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.

Script repository

Remove spaces from property value and validate it against regular expression

February 18, 2022 Views: 3766

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.

Parameters:

  • $property - Specifies the LDAP display name of the property to validate.
  • $regex - Specifies the regular expression to check against.
Edit Remove
PowerShell
$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
Leave a comment
Loading...

Got questions?

Support Questions & Answers