views:

108

answers:

2
+1  Q: 

Range validation

Suppose i ve a table like

create table { id numeric(5,3), code varchar(10) }

i ve two text box in my form for tha two field

suppose if i type 1234578 in the first text box the error has been thrown in asp.net because i crossed limit

how to validate in javascript or some otherways for that particular range validation

thank u

+1  A: 

Let's take one textbox only. Attach an 'onchange' event handler to your textbox like this:

<input type="text" onchange="handleChange(this);" />

Then declare a script for validation like this:

<script>
  function handleChange(input) {
    if (input.value > ..your_value_here..) alert ("Invalid input");
  }
</script>

Please note that the alert pop-up used here should not be actually used. Use a more subtle reminder at a more appropriate moment. The alert here is only to make things simple.

Crimson
script> function handleChange(input) { if (input.value > 5,3) alert ("Invalid input"); }</script>is it right
Domnic
No, if you want the range to be within 3 and 5, use this if clause: if(input.value < 3 || input.value > 5) alert(...
Crimson
A: 

Don't forget to validate the number at the server side, because one can always turn off Javascript at the client side and submit a number that surpasses your limit. You can also delegate this validation to the DBMS, using the CHECK constraint.

JG