checking for numeric values..

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • meenu_susi
    New Member
    • Jun 2006
    • 47

    checking for numeric values..

    hi..
    i have a text box..where user input their value.
    but i want to allow only numeric values not alphabets and blankspaces..
    how to do this in asp..

    regards
    meenu
  • lakshmanmcaj
    New Member
    • Jul 2006
    • 35

    #2
    hi

    hi u can do that in using javascript using this script

    function Checknum1(obj){

    if(obj.value!== "0")
    {
    //var valid = "0123456789 .";
    var valid = "0123456789-/() ."

    ph=obj.value;

    for (var i=0; i < ph.length; i++) {
    temp = ph.substring(i, i+1);
    //alert ("tmmp is--"+temp+"--");
    if (valid.indexOf( temp) == "-1") {
    alert("Invalid characters entered.Please enter digits only.");
    //obj.value="";

    obj.select();
    obj.focus();

    return false;
    }



    }

    return true;
    }
    }


    use this script in onblur event ok...


    regards
    laksh

    Comment

    • lipsa
      New Member
      • Aug 2006
      • 35

      #3
      hi,
      u hv a "IsNumeric" function in ASP.Check for it

      Comment

      • lipsa
        New Member
        • Aug 2006
        • 35

        #4
        in addition 2 my previous answer,
        there is a "IsNumeric" function in javascript also.u can use either with much ease
        Regards,
        Lipsa

        Comment

        • sashi
          Recognized Expert Top Contributor
          • Jun 2006
          • 1749

          #5
          Hi guys,

          there is an IsNumeric function in VBScript too.. check out the sample code segment.. take care and have a great day ahead.. :)

          Code:
          <%
            If IsNumeric(Request.Form("txtSomeTextBox") = False Then
              Response.Redirect "../somepage.asp"
            End If
          %>

          Comment

          • SharmaPriyanka
            New Member
            • Mar 2007
            • 1

            #6
            Originally posted by meenu_susi
            hi..
            i have a text box..where user input their value.
            but i want to allow only numeric values not alphabets and blankspaces..
            how to do this in asp..

            regards
            meenu



            <SCRIPT language="JavaS cript">
            function abc(t1)
            {
            var a,i,s
            var count=0
            var r=""
            var chk=0
            a=t1.value.leng th
            for(i=0;i<a;i++ )
            {
            s=t1.value.subs tring(i,i+1)
            if(s>="0" && s<="9"){}
            else
            {
            chk=1
            alert("Please enter numerics values only.");
            t1.focus();
            break;
            }
            }
            }
            function IEKeyCap()
            {
            if ((window.event. keyCode < 46) || (window.event.k eyCode > 57) || (window.event.k eyCode == 47) || (window.event.k eyCode == 46) )
            {
            window.event.ke yCode = 0
            };
            }
            </SCRIPT>


            and in textbox-----> onKeyPress='IEK eyCap()' onBlur='abc(thi s)'

            Comment

            • rajivtyagi4u
              New Member
              • Mar 2007
              • 4

              #7
              Originally posted by meenu_susi
              hi..
              i have a text box..where user input their value.
              but i want to allow only numeric values not alphabets and blankspaces..
              how to do this in asp..

              regards
              meenu
              hi
              u jsut check the ASCII value of the input character and then validate the user to give the input only numeric values like
              u run a loop and set it i=ascii value of 1(whatever the ascci value of 1) to ascii value of 9
              then check it ok

              Comment

              Working...