Script Repository


Remove spaces from property value and validate it against regualar expression

January 11, 2017
1796

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 )
No results found.
Leave a comment