On my form I have a textbox that has an RE validator for telephone numbers. The problem that just hit me like a ton of bricks, was the fact that we get a hand full of International inquiries each month. So I want to add a radio button that when clicked, will
change the field validation to allow the entry of International numbers. I assume that by clicking the radio button I should just have it turn the RE Validator off, considering there are number of possible combinations of International telephone numbers? Here's
a snippet of my current RE validation code, any ideas?
OK - there are two answers (I think) depending on what you discover about international phone numbers: 1. Disabling the validator: I'm going to do this with a checkbox but you can do it with a radio button if you want:
...
public void toggleValidation(Object sender, EventArgs e){
// I'm doing this is long winded way so you can see what's going on
if(intlNumber.Checked==true){
ph1val.Enabled=false;
} else {
ph1val.Enabled=true;
}
// the short way is ph1Val.Enabled=!intlNumber.Checked; // IIRC
}
2. Changing the regular expression
change the code in toggleValidation above to:
public void toggleValidation(Object sender, EventArgs e){
if(intlNumber.Checked==true){
ph1val.ValidationExpression=@"\d+"; // or whatever you'd use for intl
} else {
ph1val.ValidationExpression=@"((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}";
}
}
Thanks, I will give it a shot. I created an interim solution with chewing gum and duct tape. Option click hides one box and shows another seemlessly, then puts 555-555-5555 in the US text box to pass validation. (Major rig job) I want to do it the right way.
Thanks again.
I pasted the code directly from the sample you provided. The only problem is I keep getting the following error: BC30205: End of statement expected. Here's the code:
<script runat="server">
public void toggleValidation(Object sender, EventArgs e){
// I'm doing this is long winded way so you can see what's going on
if(intlNumber.Checked==true){
tbph1.Enabled=false;
} else {
tbph1.Enabled=true;
}
// the short way is tbph1.Enabled=!intlNumber.Checked; // IIRC
}
public void toggleValidation(Object sender, EventArgs e){
if(intlNumber.Checked==true){
tbph1.ValidationExpression=@"\d+"; // or whatever you'd use for intl
} else {
tbph1.ValidationExpression=@"((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}";
}
}
</script>
If you want to make this work without submitting the page, you can use the validators of my product, Professional Validation And More. Its validators have smart enabling capability based on other elements of the page, such as the mark in a radio button. For
this case, you would add your radiobuttons and textbox. Then add two RegularExpressionValidators, one for each phone number format. Each would have the new "Enabler" property set to detect the state of the radio buttons. You can see a similar example at this
URL: http://www.peterblum.com/VAM/DemoAll.aspx The Zip code field accepts the US #####-#### format until you switch to "Canada". Then it only accepts #####. All this happens without posting back. Learn more about Professional Validation And More at http://www.PeterBlum.com/VAM/Home.aspx.
--- Peter Blum
Creator of Peter's Data Entry Suite (formerly Professional Validation And More and Peter's Date Package) and Peter's Polling Package
www.PeterBlum.com
PD_Goss
Contributor
2310 Points
460 Posts
Change Validation with Option Button
Aug 05, 2003 10:52 PM|LINK
Tel#1 <asp:regularexpressionvalidator id="ph1val" runat="server" Display="Dynamic" ErrorMessage=" Check phone no" ControlToValidate="tbph1" ValidationExpression="((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}" Font-Bold="True">fozzers
Member
120 Points
24 Posts
Re: Change Validation with Option Button
Aug 06, 2003 11:44 AM|LINK
... public void toggleValidation(Object sender, EventArgs e){ // I'm doing this is long winded way so you can see what's going on if(intlNumber.Checked==true){ ph1val.Enabled=false; } else { ph1val.Enabled=true; } // the short way is ph1Val.Enabled=!intlNumber.Checked; // IIRC }2. Changing the regular expression change the code in toggleValidation above to:public void toggleValidation(Object sender, EventArgs e){ if(intlNumber.Checked==true){ ph1val.ValidationExpression=@"\d+"; // or whatever you'd use for intl } else { ph1val.ValidationExpression=@"((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}"; } }hope this helpsPD_Goss
Contributor
2310 Points
460 Posts
Re: Change Validation with Option Button
Aug 06, 2003 11:24 PM|LINK
PD_Goss
Contributor
2310 Points
460 Posts
Re: Change Validation with Option Button
Aug 08, 2003 10:35 AM|LINK
<script runat="server"> public void toggleValidation(Object sender, EventArgs e){ // I'm doing this is long winded way so you can see what's going on if(intlNumber.Checked==true){ tbph1.Enabled=false; } else { tbph1.Enabled=true; } // the short way is tbph1.Enabled=!intlNumber.Checked; // IIRC } public void toggleValidation(Object sender, EventArgs e){ if(intlNumber.Checked==true){ tbph1.ValidationExpression=@"\d+"; // or whatever you'd use for intl } else { tbph1.ValidationExpression=@"((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}"; } } </script>BTW, I'm not real familiar with C/C#. Thanks.PD_Goss
Contributor
2310 Points
460 Posts
Re: Change Validation with Option Button
Aug 11, 2003 10:04 AM|LINK
PLBlum
All-Star
30399 Points
5347 Posts
MVP
Re: Change Validation with Option Button
Aug 12, 2003 07:04 PM|LINK
Creator of Peter's Data Entry Suite (formerly Professional Validation And More and Peter's Date Package) and Peter's Polling Package
www.PeterBlum.com