1, Only numeric codes can be entered in the text box ( You can't enter a decimal point )

<input onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')">

2, You can only enter Numbers , Can enter decimal point .

<input onkeyup="if(isNaN(value))execCommand('undo')" onafterpaste="if(isNaN(value))execCommand('undo')">
<input name=txt1 onchange="if(/\D/.test(this.value)){alert(' You can only enter Numbers ');this.value='';}">

3, Number and decimal point method 2

<input type=text t_value="" o_value="" onkeypress="if(!this.value.match(/^[\+\-]?\d*?\.?\d*?$/))this.value=this.t_value;else this.t_value=this.value;if(this.value.match(/^(?:[\+\-]?\d+(?:\.\d+)?)?$/))this.o_value=this.value" onkeyup="if(!this.value.match(/^[\+\-]?\d*?\.?\d*?$/))this.value=this.t_value;else this.t_value=this.value;if(this.value.match(/^(?:[\+\-]?\d+(?:\.\d+)?)?$/))this.o_value=this.value" onblur="if(!this.value.match(/^(?:[\+\-]?\d+(?:\.\d+)?|\.\d*?)?$/))this.value=this.o_value;else{if(this.value.match(/^\.\d+$/))this.value=0+this.value;if(this.value.match(/^\.$/))this.value=0;this.o_value=this.value}">

4, Only letters and Chinese characters can be entered

<input onkeyup="value=value.replace(/[\d]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[\d]/g,''))" maxlength= name="Numbers">

5, Only English letters and numbers can be entered , Can't input Chinese

<input onkeyup="value=value.replace(/[^\w\.\/]/ig,'')">

6, You can only input numbers and English

<input onKeyUp="value=value.replace(/[^\d|chun]/g,'')">

7, There can only be up to two decimal places after the decimal point ( Numbers , Chinese can be input ), You can't enter letters and symbols :

<input onKeyPress="if((event.keyCode<48 || event.keyCode>57) && event.keyCode!=46 || /\.\d\d$/.test(value))event.returnValue=false">

8, There can only be up to two decimal places after the decimal point ( Numbers , Letter , Chinese can be input ), You can enter the operation symbol :

<input onkeyup="this.value=this.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3')">

JS Some small verification of more related articles

  1. use Vue.js Develop wechat applet : Open source framework mpvue analysis

    Preface mpvue It's a utility model Vue.js Develop the front-end framework of wechat applet . Use this framework , The developer will get the complete Vue.js Development experience , Also for H5 And applets provide the ability to reuse code . If you want to H5 The project is transformed into a small project ...

  2. js Advanced regular expressions 15 Authentication ID No (| Use of symbols :var reg=/^\d{17}[\d|X]$|^\d{15}$/)(str Methods substr)

    js Advanced regular expressions 15 Authentication ID No (| Use of symbols :var reg=/^\d{17}[\d|X]$|^\d{15}$/)(str Methods substr) One . summary 1.| Use of symbols :var reg=/^\d ...

  3. html+js Some of the little problems of

    html+js Some of the little problems of : Selectors + Traversal function : $("#taskStatusList tr:gt(0)").find("td:eq(3)").find(&q ...

  4. About Jquery.validate.js Dynamic deletion verification in remove Methodical Bug

    utilize Jquery.validate.js To do dynamic verification , Need specific circumstances , Delete add opAmount You have to work on it Check $("#form").validate({ rule ...

  5. {{angular.js Using skills }} - Extensions based on verification framework (w5cValidator)

    Opening remarks : angular.js  It's the front end of Google js MV* frame , I also do this year  worktile  It's only when I'm young that I'm in touch , At first, the technology was ready to be used backbone( After all, a lot of big companies are using him , And it's more ...

  6. use js Realization 2048 Little games

    use js Realization 2048 Little games Note warehouse :https://github.com/nnngu/LearningNotes 1. Introduction to the game 2048 Is a kind of leisure puzzle digital superposition game .( At the end of the paper, the source code and demo address are given ) ...

  7. 【 turn 】 utilize three.js An attempt to develop wechat games

    Preface It's a use of three.js An attempt to develop wechat games , It's not a tutorial , It's just a note . WeChat WeChat 6.6.1 Wechat games are introduced , In the early stage, a number of small games with good quality were launched . I'm looking up the ...

  8. js Array de duplication tips

    js Array de duplication tips Intro There is a problem today , We need to de duplicate the data , I want to see if there is any convenient way , Sure enough, there are some gains . Question Problem description : I have this data : [ { "Pro ...

  9. MPVUE - Use vue.js Develop wechat applet

    MPVUE - Use vue.js Develop wechat applet What is? mpvue? mpvue Meituan comments is a front-end team open source use Vue.js Develop the front-end framework of wechat applet . The framework provides a complete Vue.js Development experience , Development ...

Random recommendation

  1. Set up git No submission Modify the permission file

    vim .git/config  Open file

  2. Two Fragment How to transfer data between

    FragmentA start-up FragmentB, After doing some selection operations , return FragmentA, Need to put FragmentB The selected data is sent back . What can I do ? Fragment There's no direct communication between them , Must pass Activit ...

  3. Android ant Automatic packaging crunch Report errors

    terms of settlement : modify SDK_HOME/tool/ant/build.xml. <property name="aapt.ignore.assets" value="&l ...

  4. No more misinformation ,GET and POST The real difference

    No more misinformation ,GET and POST The real difference Most of the answers on the Internet are wrong stay 2012 year 05 month 03 Japan It was written that day     There has been a 19940 I read it for the first time thank   Reference or original  www.cnblogs.com   service ...

  5. windows Kernel snooping

    windows It's a very good OS, Starting today , I want to share with you windows The joy it brings us ! I just share my study notes with you , One is to make yourself understand more deeply windows, And then there are some omissions , Wang Da ...

  6. be familiar with Git Use

    be familiar with Git Use installation git Please modify the user name and mailbox command for submission :git config --global user.name "Your Name" git config --global ...

  7. Robot Framework And Web Interface automation test learning notes : How to judge the selected state of a radio box

    Radio button is a common html Elements , A set of radio buttons is often provided in a web page to make options . In this way, in the automatic test case, it is necessary to judge whether the currently selected button is consistent with the expected one . You can do this : ${value}    Get Element ...

  8. cocos2d-x Game cycle and schedule

    Each game has a program execution cycle that continues . This is the director object to manage very much . In the scenario of sports hypothesis, the spirit is needed , We can use timers in the game circle (Scheduler) Sprites and other objects . because Node Class encapsulation Scheduler class ...

  9. Introduction to interface testing (5)---- New framework refactoring , Use lightweight HTTP Development Library Unirest

    The following problems were found in the use of the first framework before : One .   frame 1 shortcoming : 1. The login account is written differently by everyone , Once the user is modified in the test environment , Then the use case fails 2. Every time I read and visit the website , Need to be in the same java File switch test ...

  10. understand Linux Operating system development stage

    One . History of hardware and software A computer consists of hardware and software Two .Linux History of development Linux The operating system is Unix A clone system of the operating system . It was born in 1991 Year of 10 month 5 Japan ( It's just the first time it's officially announced ). I'll borrow it later ...