Script repository
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.