Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using a variable in regular expression validator

Status
Not open for further replies.

djtom2000

Programmer
Feb 2, 2002
13
0
0
GB
Hi,

I am using regular expression validator to carry out some validation and have some code like this:

<asp:regularexpressionvalidator id="regMobileNo" ControlToValidate="txtMobileNo" ValidationExpression="[0-9]{10,15}"

In my aspx.cs page I have added the following line of code to pull my vale from the config, e.g. 4,6

String MobileValidation = ConfigurationSettings.AppSettings["MobileValidation"].ToString();

In the aspx file I want to refer to the variable to dynamically refernce this, e.g. replace 10,15 that is currently hard coded.

How do I do this?

Thanks
 
Code:
protected override void OnInit(EventArgs e)
{
   base.OnInit(e);
   string digits = ConfigurationSettings.AppSettings["MobileValidation"];
   regMobileNo.ValidationExpression = "[0-9]{"+digits+"}";
}

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top