Enter numbers in the HTML restricted text box

Source: Internet
Author: User
<! Doctype HTML public "-// W3C // dtd html 4.0 transitional // en" >
< Html >
< Head >
< Title > New Document </ Title >
< Meta Name = "Generator" Content = "Editplus" >
< Meta Name = "Author" Content = "" >
< Meta Name = "Keywords" Content = "" >
< Meta Name = "Description" Content = "" >

<ScriptAng= "JavaScript">

Function Justnumbertext (){
If ( ! (Window. event. keycode > =   48 ) && (Window. event. keycode <=   57 )) | Window. event. keycode =   10   | Window. event. keycode =   13 )){
Window. event. keycode =   0 ;

Alert ("Enter a number!");Return False;
}
}

FunctionCheckcode (){

var value = event. keycode;

If ( ! (value 47 ) & (value 58 ) {

Alert ("Enter a number!");Return False;

}

}
</Script>

< Script Language = Javascript >  
Function VIS ()
{
If (Isnan (form1.t1. Value ))
{
Alert ( ' The telephone number must be in digital format. ' )
Form1.t1. Focus ()
Return   False  
}
If (Form1.t1. value. Length >   11 )
{
Alert ( ' The telephone number should be 11 characters long. ' )
Form1.t1. Focus ()
Return   False  
}
}
</ Script >  

</Head>

body >
form action = "? " method =" Post " name =" form1 " >

<InputName= "Txt1"Onchange= "If (/\ D /. test (this. value) {alert ('enter a number for the phone number '); this. value = ''; this. focus ()}">

<InputOnkeyup= "If (isnan (value) Execcommand ('undo ')"Onchange= "If (/\ D/. Test (this. Value) {alert ('only numbers allowed '); this. value = '';}">

<InputOnkeydown= "If (isnan (value) Execcommand ('undo ')"Onchange= "If (/\ D/. Test (this. Value) {alert ('only numbers allowed '); this. value = '';}">

<InputOnkeyup= "This. value = This. value. Replace (/\ D/g ,'')"Onafterpaste= "This. value = This. value. Replace (/\ D/g ,'')">

input onkeypress =" If (event. keycode <48 | event. keycode> 57) {alert ('phone number can only be entered number'); event. returnvalue = false;} " onkeyup =" this. value = This. value. replace (/[^ \ D *]/, '')" >

input onkeypress =" If (event. keycode <48 | event. keycode> 57) {alert ('phone number can only be entered number'); event. returnvalue = false;} " onpaste =" Return false; " onkeyup =" this. value = This. value. replace (/[^ \ D *]/, '')" >

<InputType= "Submit"Name= "Submit"Value= "Submit">

</Form>
</Body>
</Html>

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.