Click here to Skip to main content
15,891,253 members
Articles / Web Development / ASP.NET
Tip/Trick

ASP.NET client-side validation against a dynamically loaded list

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
18 Sep 2010CPOL 7.7K   1  
Use RegularExpressionValidator to validate user input against a dynamic list of values.
If you need to validate some user input against a set of allowed values, you can use the RegularExpressionValidator by setting its ValidationExpression as follows:

EUR|USD|AUD|CHF


The '|' symbol delimits the set of allowed values in a regular expression.

If you need to load the list of allowed values from a database, config file or other source, you can do so, and simply set the ValidationExpression property of the RegularExpressionValidator at runtime.

VB
Dim currencyDAL As New CurrencyDAL()
Dim currencies As List(Of String) = currencyDAL.SelectAll()
Dim expression As String = String.Join("|", currencies.ToArray)
currencyValidator.ValidationExpression = expression


Simple.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Ireland Ireland
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --