Only text boxes with numbers and decimal places can be entered
Html code
- <Html>
- <Head>
- <Meta http-equiv = "content-Type" content = "text/html; charset = gb2312">
- </Head>
- <Body>
- <! -- Add the following code to the <body> and </body> -->
- Only text boxes with numbers and decimal places can be entered:<InputOnkeyup = "value = value. replace (/[^ d.]/g ,'')">
- </Body>
- </Html>
<Html>
Decimal point judgment
1. The first input must be a number, not a decimal point. Example: 111
2. There cannot be multiple. Consecutive, but only one. Example 12... 1
3. There is not much one. in different places. For example, 12.1.1
Html code
- <Html>
- <Head>
- <Meta http-equiv = "content-Type" content = "text/html; charset = gb2312">
- <Title> javascript can only enter numbers and decimal places </title>
- <ScriptLanguage = "JavaScript" type = "text/javascript">
- Function clearNoNum (obj)
- {
- // Replace all non-numeric values first, except numbers and.
- Objobj. value = obj. value. replace (/[^ d.]/g ,"");
- // Ensure that the first digit is a number instead of a number.
- Objobj. value = obj. value. replace (/^./g ,"");
- // Ensure that there is only one and no more.
- Objobj. value = obj. value. replace (/. {2,}/g ,".");
- // Ensure that the message appears only once, but not more than twice.
- Objobj. value = obj. value. replace (". "," $ # $ "). replace (/. /g ,""). replace ("$ # $ ",". ");
- }
- </Script>
- </Head>
- <Body>
- <! -- Add the following code to the <body> and </body> -->
- Only text boxes with numbers and decimal places can be entered:<InputId = "input1" onkeyup = "clearNoNum (this )">
- </Body>
- </Html>
<Html>