Sometimes we might face a scenario where we find the need to prevent users from entering special characters in some fields. For example we want to restrict users from using the “%, &, @” characters in the Bill ‘Description’ field.
As we know we can use Smart Rules to add user based validations to the standard screens. They allow us to write run-time validations. Using Smart Rules, we can ensure that the standards of our business processes are achieved.
- strtolower(parameter) : To return the string in lowercase.
- strtoupper(parameter) : To return the string in Uppercase.
- strlen(parameter) : To return the length of string.
- substr(parameter,start,[length]) : To return a substring whose length starts from the character at the position provided as start and goes upto the length of characters mentioned. Length is the end of string if not mentioned.
- right(parameter,length) : To return a substring starting from the character at position provided as length, counting from end of the string.
- left(parameter,length) : To return a substring starting from the character at position provided as length, counting from the beginning.
- strstr(parameter,token) : To check if the substring/token is present within the string. For checking case sensitivity as well use stristr(parameter,token).
We can use strstr(parameter, token) methodwithin Smart Rule condition for preventing special charactes. This method returns a Boolean value (true/ false) based on if the mentioned token exists within the parameter string. Make sure to write strstr all in lowercase as the method strstr() is case-sensitive.
Follow the steps below:
- Add a new Smart Rule on the desired object (e.g: AP Bill) by navigating into Platform services.
- Select Events Add and Edit. Choose the message type as “Error”.
- Write the following condition and Save.
- Now add a bill to check how our validation is working. Fill in the desired details and mention any or all of %, & and @ symbols in the description field and then click Post.
Above error is displayed thus restricting Users from entering %, &, @ characters in Description field. All other special characters are allowed though.
This way using a Smart Rule we can easily validate the Bills to check if the Users bide by the characters we want to allow in Description field.