Input box can only enter numbers, decimal point, minus sign

function checkValue(val){
    this.val=val;
}
var discountValue=new checkValue("");// Define global variables, record the last legitimate values
function clearNoNum(obj,isMinus,objValue)
{
        var key = event.keyCode;
        var value = obj.value;
        // Defining legal press list, including a small keypad  0-9, The main keyboard area 0-9, decimal point  , The negative sign, bottom, left, and right arrow keys  ,home,end,delete
        var mayKey =new Array(8,35,36,37,38,39,40,46,48,49,50,51,52,53,54,55,56,57,96,97,98,99,100,101,102,103,104,105,110,190);
        if((key==189||key==109)&&isMinus&&objValue.val.length==0){// According to isMinus determine whether cannot enter a negative number  , If we can judge the negative sign is in the first
                objValue.val = value;
                return false;
        }
        for(var i=0;i<mayKey.length;i++){
                if(key==mayKey[i]){
                        objValue.val = value;
                        return false;
                }
        }
        document.execCommand('undo');// If the keyboard is not click on the above button, clear the value of the input box
        obj.value = objValue.val;// Set the global variable's value to the input box to last; a legal value assigned to an input box again
}

function discountCheck(obj){
        clearNoNum(obj,false,discountValue);
}

Call page methods:

<input type="text" onkeyup="discountCheck(this)" />
分类:Web 时间:2010-06-07 人气:241
分享到:
blog comments powered by Disqus

相关文章

  • 如何用正则取input type="text"中的value 2014-02-04

    1.如何通过正则取input type="text"中的value呢? 2.如何过滤掉input type="checkbox"的标签? 这样只能达到正则取input type="text"中的value可是不能过滤掉input type="checkbox"的标签! alert [Ctrl+A 全选 注:如需引入外部Js需刷新才能执行] alert [Ctrl+A 全选 注:如需引入外部Js需刷新才能执行] 解决: alert [Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]

  • input type = "image" input type = "submit" difference 2011-01-09

    input type = "image" input type = "submit" difference input type = "submit" button on the form is submitted, using the system default style, input type = "image" can also submit the form, but the use of user-sp

  • JS received input through the input box with the mouse to select the contents of the 2010-10-27

    <! DOCTYPE HTML PUBLIC "- / / W3C / / DTD XHTML 1.0 Strict / / EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd "> <HTML xmlns = " http://www.w3.org/1999/xhtml "> <HEAD> <TITLE> New Documen

  • Change the text input file, IE firefox compatible 2010-05-27

    <input type="text" /> <input type="button" value="Bowser" size="40" /> <input type="file" onchange="document.getElementById('txt1').value=document.getElementById('my-fi ...

  • Dynamically change the input type tag attributes (such as the password to text) 2010-12-25

    <HTML> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <script> function removeSubmitFocus () { document.all ('pass'). outerHTML = "<input type = text name ='

  • jQuery version of the text input box checker Input Check 2011-01-14

    Original Address: http://www.cnblogs.com/linzheng/archive/2010/10/17/1853574.html Very good, the next collection /** * power by wooshoo copyright 2008-2009 * Program name :JQuery Dedicated input checker * Content : Specifically input[text password hi

  • input type = file tag ban the user to manually enter 2010-08-02

    Surface is the method used: 1. Substitution Using hidden <input type="file"/> control, then a read-only text box and a button to simulate <input type="file"/> function. <Input type = "file" name = "fi

  • js input box control input can only enter a number or decimal number decimal point (transfer) 2010-08-08

    JS judge only numbers and decimal points 1. Text box can only enter the numeric code (decimal point can not be input) <input onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g

  • input type description 2010-11-19

    Form Input in the form that an input object, its type and with different sub-Type text input box, the password input box, radio / check box, and submit / reset buttons, the following introduced one by one. 1, type = text Input type is text, this is the mo

iOS 开发

Android 开发

Python 开发

JAVA 开发

开发语言

PHP 开发

Ruby 开发

搜索

前端开发

数据库

开发工具

开放平台

Javascript 开发

.NET 开发

云计算

服务器

Copyright (C) codeweblog.com, All Rights Reserved.

CodeWeblog.com 版权所有 黔ICP备15002463号-1

processed in 0.109 (s). 14 q(s)