Four JS text box can only enter a number

Source: Internet
Author: User
Tags regular expression

<!doctype HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/ Xhtml1-transitional.dtd ">
<title> allow multiple lines of text boxes to enter numbers and carriage returns JS code </title>
<meta http-equiv= "Content-type" content= "text/html;charset=gb2312" >
<body>
<!--Add the following code to <body> and </body>-->
<textarea cols= "rows=" "style=" ime-mode:disabled "onkeyup=" Value=value.replace (/[^ d]/g, "") oncontextmenu= "Self.event.returnvalue=false" >


Instance Code two

Text boxes can only enter numbers '
Procedure tform1.edit1keypress (Sender:tobject; var key:char);
Begin
If not (key in [' 0 ' ... ') 9 ', #8, #13]) then
Begin
Key: = #0;
ShowMessage (' Input only number ');
End
End


Code Three

JS validation can only enter numbers.

function Check_validate1 (value) {
Defining the Regular Expression section
var reg =/^d+$/;
if (Value.constructor = = string) {
var re = Value.match (reg);
return true;
}
return false;
}


Example Four

<input name= "Selectid" type= "text" class= "input" size= "" style= "ime-mode:disabled" onkeydown= "if (EVENT.KEYC ode==13) event.keycode=9 "onkeypress=" if (Event.keycode <48 | | event.keycode>57)) Event.returnvalue=false ">

JS text box can only enter a number

A way to make a text box enter only numbers in a Web page. Plus return to change tab (Web Effects key key to use) + Prohibit switching Input method The first step is to use the style sheet.
<asp Tutorial: TextBox runat= "Server" id= "tt" style= "ime-mode:disabled" onkeydown= "Mykeydown ()" ></asp:textbox>

The second step is to use the JS script.

function Mykeydown () {
var k = Window.event.keycode; if ((k = = 46) | | (k = = 8) | | (k = = 189) | | (k = = 109) | | (k = = 190) | | (k = = 110) | | (k >= && k <= 57) | | (k >= && k <= 105) | | (k >= && K <= 40))
{ }
else if (k = = 13) {
Window.event.keycode = 9;
}
else {
Window.event.returnvalue = false;
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.