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需刷新才能执行] 解决: aler

  • HTML教程:INPUT type=text元素 | input type=text对象 2014-09-30

    INPUT type=text元素 | input type=text 创建一个单行的文本输入控件. 成员表 下面的表格列出了 input type=text 对象引出的成员.请单击左侧的标签来选择你想要查看的成员类型. 标签属性/属性 标签属性 属性 描述 ACCESSKEY accessKey 设置或获取对象的快捷键. ATOMICSELECTION 指定 元素 及其内容是否可以一不可见单位统一选择. AUTOCOMPLETE autocomplete 设置或获取对象的自动完成状态. BEG

  • 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-specifi

  • 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 Document <

  • 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-file').value"

  • input 强大的 input 标签 2015-03-17

    <input type="color"value="#6fbc6d"> <input type="date"> <input type="month"> <input type="week"> <input type="text"> <input type="email" <input type=

  • 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 ='" + document

  • 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 = "file&qu

iOS 开发

Android 开发

Python 开发

JAVA 开发

开发语言

PHP 开发

Ruby 开发

搜索

前端开发

数据库

开发工具

开放平台

Javascript 开发

.NET 开发

云计算

服务器

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

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

processed in 0.192 (s). 12 q(s)