There's a lot on the Internet about Only numbers can be entered in the text box Of , I looked for it again today , I found that there was something wrong with the previous way of writing !

onkeypress="if (event.keyCode<48 || event.keyCode>57) event.returnValue=false;"

If you type Chinese characters , Still pass !

Now there are two ways to write it : Refuse . / ? = + ` ~ And Chinese characters ( So far, we've measured , It seems that you can only input Chinese characters )

onkeyup='value=value.replace(/[^\d]/g,"") ' 
onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))"
onkeyup="this.value=this.value.replace(/\D/g,'')" 
onafterpaste="this.value=this.value.replace(/\D/g,'')"
 <asp:TextBox ID="Label_glfy" Width="80px" runat="server" Text='' onkeyup='value=value.replace(/[^\d.-]/g,"") '
onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d.-]/g,''))"></asp:TextBox>

You can enter    The sign     as well as     decimal point     I recommend this

<asp:TextBox ID="txtNeedPage" Width="20px" runat="server" onkeyup='value=value.replace(/[^\d]/g,"") '
onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))"
></asp:TextBox>
<asp:TextBox ID="txtNeedPage" Width="20px" runat="server" onkeyup='value=value.replace(/[^\d]/g,"") '
onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))"
></asp:TextBox>

perhaps

<asp:TextBox ID="txtNeedPage" Width="20px" runat="server" onkeyup="this.value=this.value.replace(/\D/g,'')"
onafterpaste="this.value=this.value.replace(/\D/g,'')"
Text="<%#((GridView)Container.Parent.Parent).PageIndex + 1 %>"></asp:TextBox>

java The latter says jsp in :

<tr>
<td>
Age :
</td>
<td>
<input type="text" name="age" id="age_" onkeyup='value=value.replace(/[^\d]/g,"") '
onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))"/>
</td>
</tr>

Just as practical !

C# Limit text boxes to numbers :

 if (!(Char.IsNumber(e.KeyChar) || e.KeyChar == '\b'))
{
e.Handled = true;
}

txtBox Of KeyPress event !

textbox More related articles on solving the problem of constrained input values

  1. WPF Custom controls and styles (3)-TextBox &amp; RichTextBox &amp; PasswordBox style 、 watermark 、Label label 、 Function extension

    One . Preface . preview Affirming :WPF Custom controls and styles is a series of articles , There is some connection between the front and the back , But most of them are published step by step from simple to complex , If you don't understand, please refer to the previous articles in this series , At the end of the article are some links . This article is mainly about the text ...

  2. WPF Implement with style TextBox Virtual prompt effect of

    [ Copyright notice ] This article is original for bloggers , No commercial use without permission , If reproduced, please indicate the source . Say a lot of software and website can realize fictitious clew , Well, I started the term myself , Because I don't know how to describe this effect . Effect description : stay TextBox no ...

  3. 【 turn 】WPF Custom controls and styles (3)-TextBox &amp; RichTextBox &amp; PasswordBox style 、 watermark 、Label label 、 Function extension

    One . Preface . preview Affirming :WPF Custom controls and styles is a series of articles , There is some connection between the front and the back , But most of them are published step by step from simple to complex . This paper mainly develops the style of text input control , And related extended function development , The main contents include : Basic text ...

  4. UWP&amp;WP8.1 Basic controls —TextBlock and TextBox

    TextBlock: Text display control , It has powerful functions TextBox: Text input control . These two controls are the most commonly used base controls . TextBlock Basic usage : Open one UWP project , stay XAML You can design pages from the toolbox ...

  5. To teach you ASP.NET How to prevent injection attacks in

    You should verify all untrusted input in the program . You should assume that all user input is illegal . Users can provide form fields in the application , Query string , client cookies And browser environment values such as user agent strings and IP Address, etc . Weak input check is usually a note ...

  6. [ collect ]MVC3 HTML Auxiliary method collection

    1. Jump Links @Html.ActionLink("linkText","actionName",routeValues,htmlAttributes) e.g& ...

  7. WPF And Binding In-depth discussion

    original text :http://blog.csdn.net/fwj380891124/article/details/8107646 1,Data Binding stay WPF Status in The essence of program is data + Algorithm . The data will be in ...

  8. SharePoint Customize WebPart Connection between

    1. establish SharePoint Solution , Add two WebPart They are used to send and receive : 2. Send the value of WebPart Need to inherit from IWebPartField( Of course , You can also choose according to your needs IWebPartField,I ...

  9. WPF Of Binding Function parsing

    1,Data Binding stay WPF Status in The essence of program is data + Algorithm . The data will be stored . Logic and interface flow between the three layers , So from a data point of view , These three layers are very important . But the algorithm is 3 The distribution in the layer is not uniform , For one 3 Layer structured ...

Random recommendation

  1. TODO:Linux install PHP MongoDB drive

    TODO:Linux install PHP MongoDB drive PHP Conducive to learning , Widely used , Mainly applicable to Web Development field . MongoDB The main goal of is in the key / Value storage ( Provides high performance and high scalability ) And the traditional RDBMS System ...

  2. Xiong Jun JavaScript Plug in development ------( In the actual combat part DXJ UI ------ ItemSelector)

    One , Opening analysis Hi, Hello everyone ! I'm seeing you again , Remember the first two articles . It is mainly about “jQuery How to develop plug-ins ”, And the combination of process design and object-oriented design is How to design a plug-in , Both ways are advantageous ...

  3. Pytorch Series of tutorials - Use character level RNN Categorize names

    Preface This series of tutorials is pytorch Translation of official documents . This article corresponds to the official website address :https://pytorch.org/tutorials/intermediate/char_rnn_classification_t ...

  4. Ruffian scale embedded : Turn on NXP-MCUBootUtility The tool HAB encryption - CST( Chinese English bilingual )

    1 Reason for enabling HAB encryption function Why open HAB encryption NXP-MCUBootUtility is a tool designed fo ...

  5. jumpserver piece -- install ( High availability mariadb+haproxy)

    1. demand In order to solve the problem of various landing methods at present , Firewall configuration is complex , There is no record of historical operation , Confusion of user rights and so on 2. Jumpserver Test environment construction 2.1. Environmental Science os:CentOS release 6.8 mini ...

  6. P1744 Buy special offers Answer key ( Explain graph theory )

    The super elementary problem of graph theory ( The template questions ) The shortest path of the template problem What's the picture ?( Symbols on white paper ?) For a possession n An undirected connected graph with two vertices , It must have more sides than n-1 strip . If you choose n-1 side , So that the undirected graph is still connected , By n Two vertices and this n- ...

  7. Mysql Big text types

    TEXT One BLOB or TEXT Column , Maximum length is 65535(2^16-1) Characters . MEDIUMTEXT One BLOB or TEXT Column , Maximum length is 16777215(2^24-1) Characters . LONGTEXT ...

  8. bootstrap Simple to use layout 、 grid system 、modal Tag page and other common components

    <!DOCTYPE html> <html> <head> <title>bootstrap</title> <!-- introduce boots ...

  9. Iterators and generics for

    Iterator and closure function allwords() local line=io.read() return function() while line do local s,e=strin ...

  10. Codeforces Round #493 (Div 2) (A~E)

    Catalog Codeforces 998 A.Balloons B.Cutting C.Convert to Ones D.Roman Digits E.Sky Full of Stars( A class Count ) C ...