Solved

Numeric validation

Posted on 2004-08-10
4
9,203 Views
Last Modified: 2011-08-18
Hi,

The folloiwng code displays data in an asp form from database for updating purpose. I want to force user to enter a number (no decimals or negative or zeros) in the "QtyOut_<%=iLp%>" fields. Could anyone pls. help me?

Zero is allowed only if user selected the check boxes in the form "Del_<%=iLp%>".

          <%if not rst3.EOF then
               iLp = -1
               while not rst3.EOF
                    iLp = iLp + 1%>
                    <TR>
                         <TD width="40" height="1" align="center"><%=rst3.AbsolutePosition%></TD>
                         <TD width="150" height="1">
                              <INPUT name="PartNo_<%=iLp%>" ReadOnly value="<%=server.HTMLEncode(rst3("PartNo"))%>">
                         </TD>
                         <TD width="151" height="1">
                              <INPUT name="f_1_<%=iLp%>" value="<%=server.HTMLEncode(rst3("ProductName"))%>" readonly>
                         </TD>
                         <TD width="100" height="1">
                              <INPUT size=5 name="QtyOut_<%=iLp%>" value="<%=rst3("QtyOut")%>">
                              <input type="hidden" name="OldQtyOut_<%=iLp%>" value="<%=rst3("QtyOut")%>">
                              <input type="hidden" name="ROL_<%=iLp%>" value="<%=rst3("ROL")%>">
                         </TD>
                         <TD align="center">
                              <INPUT type="checkbox" name="Del_<%=iLp%>" value="True">
                              <INPUT type=hidden name="ID_<%=iLp%>" value="<%=rst3("ID")%>">
                         </TD>
                    </TR>
                    <%rst3.MoveNext
               Wend%>
               <tr>
                    <td colspan="5" align="right">
                         <input type="hidden" name="ItemCount" value="<%=iLp%>">
                         <input type="hidden" name="Action" value = "Update">
                    </td>
               </tr>
          <%end if%>

hafs.
0
Comment
Question by:ayha1999
4 Comments
 
LVL 13

Expert Comment

by:StormyWaters
ID: 11763667
Do you want the user to be able to type any character in the box and then it checks it on submit or do you want it to only allow 1-9 and maybe 0 in the box and all other characters don't work?
0
 
LVL 33

Accepted Solution

by:
knightEknight earned 30 total points
ID: 11763817
use this onblur event on your inputs:

<INPUT type="text" name="numeric" onblur='this.value=this.value.replace(/[^\d]*/gi,"");' />
0
 
LVL 16

Expert Comment

by:jaysolomon
ID: 11769597
<INPUT type="text" name="numeric" onblur="if(isNaN(this.value)){this.value = '';} />
0
 
LVL 7

Author Comment

by:ayha1999
ID: 11781401
Hi,

I want to force user to enter numeric values in the "QtyOut_<%=iLp%>" fields.

It should be something like this;

function mySubmit(obj)
{
     var theForm=obj.form;
     var p1=/^col1_/;
     var num=/^[1-9]\d*/;
     var oldCol1= new Array();
     for(var i=0;i<theForm.elements.length;i++)
     {
          if(p1.test(theForm.elements[i].name))
          {
               if(theForm.elements[i].value!="" && theForm.elements[i+1].value=="")
               {
                    alert("Please enter a valid quantity");
                    theForm.elements[i+1].focus();
                    return false;

But if user seletected <INPUT type="checkbox" name="Del_<%=iLp%>" value="True"> then 0 is allowed.

hafs
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question