RobinAtTech
RobinAtTech

Reputation: 1329

WPF Validation, Regular expressions, repeating entries

I am validating a textbox in WPF. The data should be entered in the textbox something like 2X1500 3X3300 7X3699 there may be 'n' number of entries in a single

I can validate for a single entry[2x1500] and I found the regular expression as @"^\d{1,10}X\d{1,10}$". How to do a validation if they entered multiple entries in a single textbox something like I explained earlier[2X1500 3X3300 7X3699]

Upvotes: 0

Views: 76

Answers (2)

slugster
slugster

Reputation: 49974

For something like this I would suggest you use bindable validation rules, which is a feature built in to WPF but seldom exploited.

I illustrate how to do this in this blog post, quite simply you use a class that extends ValidationRule, you can also implement public properties on this bindable rule which allow you to declaratively specify the regex to use. This then ties your validation logic and actions together in a nice encapsulated and reusable way.

Upvotes: 1

user2268788
user2268788

Reputation: 266

@"^((\d{1,10}X\d{1,10})\s?)+$"

Upvotes: 1

Related Questions