D
D. Shane Fowlkes
I have a asp:textbox which I've applied a javascript function to strip off
all non-numeric chanarcters. The js function is triggered with the textbox's
onblur attribute. I also have a rangevalidator to make sure the value
entered is numeric and is between 1 & 999999.
The custom js works fine. If someone enters 7,777 or even something invalid
like 7,7,7,7, all the commas are stripped off as soon as they tab off the
field and all that is left is 7777. The problem is that ANY data entry
containing anything other than the acceptable range WITH commas, it still
triggers the asp:rangevalidator error.
So if they enter 7,000, the comma is stripped off BUT the rangevalidator is
still triggered when the field is tabbed off. How can I prevent this? Or
should I ask - how can I get the rangevalidator to test upon the lost focus
of the field. It sort of does this anyway because when I make a
"correction" and type 7000 again (typing exactly what is there) and tab off,
the rangevalidator goes away.
Thoughts? What would you do?
The custom js:
function tmt_reFormat(f,re,s){
fv=MM_findObj(f).value;var rex=new RegExp(unescape(re),"g");
if(rex.test(fv)){MM_findObj(f).value=fv.replace(rex,unescape(s));}
}
On page_load:
txtPopulation.Attributes.Add("onblur",
"tmt_reFormat('txtPopulation','%5B%5E%5Cd%5D','')")
The page:
<asp:TextBox ID="txtPopulation" runat="server">0</asp:TextBox>
<asp:RequiredFieldValidator ID="PopulationRequired" runat="server"
ControlToValidate="txtPopulation" ErrorMessage="*Population is required."
Display="Dynamic"><img width="25" height="18" border="0"
src="../assets/icons/error.gif" align="absmiddle"
/></asp:RequiredFieldValidator>
<asp:RangeValidator ID="PopulationValidator" runat="server"
ControlToValidate="txtPopulation" ErrorMessage="*Population must be numeric
and between 1 and 99999999. " MaximumValue="99999999" MinimumValue="1"
Type="Integer" Display="Static" SetFocusOnError="True"><img width="25"
height="18" border="0" src="../assets/icons/error.gif" align="absmiddle"
/></asp:RangeValidator>
all non-numeric chanarcters. The js function is triggered with the textbox's
onblur attribute. I also have a rangevalidator to make sure the value
entered is numeric and is between 1 & 999999.
The custom js works fine. If someone enters 7,777 or even something invalid
like 7,7,7,7, all the commas are stripped off as soon as they tab off the
field and all that is left is 7777. The problem is that ANY data entry
containing anything other than the acceptable range WITH commas, it still
triggers the asp:rangevalidator error.
So if they enter 7,000, the comma is stripped off BUT the rangevalidator is
still triggered when the field is tabbed off. How can I prevent this? Or
should I ask - how can I get the rangevalidator to test upon the lost focus
of the field. It sort of does this anyway because when I make a
"correction" and type 7000 again (typing exactly what is there) and tab off,
the rangevalidator goes away.
Thoughts? What would you do?
The custom js:
function tmt_reFormat(f,re,s){
fv=MM_findObj(f).value;var rex=new RegExp(unescape(re),"g");
if(rex.test(fv)){MM_findObj(f).value=fv.replace(rex,unescape(s));}
}
On page_load:
txtPopulation.Attributes.Add("onblur",
"tmt_reFormat('txtPopulation','%5B%5E%5Cd%5D','')")
The page:
<asp:TextBox ID="txtPopulation" runat="server">0</asp:TextBox>
<asp:RequiredFieldValidator ID="PopulationRequired" runat="server"
ControlToValidate="txtPopulation" ErrorMessage="*Population is required."
Display="Dynamic"><img width="25" height="18" border="0"
src="../assets/icons/error.gif" align="absmiddle"
/></asp:RequiredFieldValidator>
<asp:RangeValidator ID="PopulationValidator" runat="server"
ControlToValidate="txtPopulation" ErrorMessage="*Population must be numeric
and between 1 and 99999999. " MaximumValue="99999999" MinimumValue="1"
Type="Integer" Display="Static" SetFocusOnError="True"><img width="25"
height="18" border="0" src="../assets/icons/error.gif" align="absmiddle"
/></asp:RangeValidator>