revalidate on textbox's lost focus??

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>
 
S

S. Justin Gengo

Shane,

Change your custom JS to fire "OnKeyDown".

That way any commas, etc. will be removed immediately and you won't run into
the conflict of the built in validator firing first when tabbing off the
control.

Regards,

--
S. Justin Gengo
Web Developer / Programmer

Free code library:
http://www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top