Solved

Numeric validation

Posted on 2004-08-10
4
9,201 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
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…

867 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now