Last week, I posted an example of using a Regular Expression to control the input of numbers into a TextBox. A couple of my fellow disciples commented that they’d just use a Regular Expression Behavior or DP to control the input of the text. Now, there are a couple of reasons that I’d use the dedicated
The first reason is that it’s a simple control for those that aren’t comfortable writing Regular Expressions. After all, why should you write a complex Regular Expression when I can write one for you?
The second reason is that the numeric control is internationalised from the get-go. I’ve already taken care of sorting out the whole internationalised decimal place issue, so you don’t have to worry about it with your Regular Expression.
Saying that, the Regular Expression behavior is a cracking idea, and one I could kick myself for not thinking of earlier. So, in order to add Regular Expression functionality in your
TextBox, all you need do is add the following code:
As you can see, it’s similar in code to the other behaviour. The only real difference in it is that it has a mask string which is used to add the Regular Expression text.