Archive for March, 2012

In the new self-service portal (SSP) in Service Manager 2012 you have the option to validate input using a custom regular expression. To possibly save you some time when doing so I would like to share something important with you.

Always start you expression with caret (^) and end with a dollar sign ($). This makes sure that the input given by the user is an exact match to your expression.
^ – A caret matches the position at the beginning of the input string.
$ – A dollar sign matches the position at the end of the input string.

Example expression:
\d

The expression above can be used to find all digits in a text. If you would use that as a validation expression for a text field in Service Manager, according to Service Manager the input would be valid as long as a digit is written into the field. Here’s a pitfall, this means that a user can write whatever he/she wants before and after the digit. Normally this probably isn’t what you’re looking for when validating the input. Normally you would want to validate the complete input. Adding the caret and the dollar sign (^\d$) will make sure that nothing else goes into the text field than a digit.

If you want to try your expressions out before implementing them, here’s one of my favorites:
http://derekslager.com/blog/posts/2007/09/a-better-dotnet-regular-expression-tester.ashx

Other resources:
http://msdn.microsoft.com/en-us/library/ff650303.aspx
http://www.regular-expressions.info

Categories : Service Manager
Comments (0)