Some small verification of JS

Source: Internet
Author: User

1, the text box can only enter a numeric code (the decimal point can not be entered)

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

2, only the number can be entered, the decimal point will be lost.

<input onkeyup="if (IsNaN (value)) ExecCommand (' Undo ')" onafterpaste="if (IsNaN (value)) ExecCommand (' Undo ')"><input name=txt1 onchange="if (/\d/.test ( This.value) {alert (' Input number only '); this.value= ';} ">

3, digit and decimal method two

<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+)?)? $/)) 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+)?)? $/)) 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 kanji can be entered

<input onkeyup=""onbeforepaste="clipboarddata.setdata (' text ', Clipboarddata.getdata (' text '). Replace (/[\d]/g, ')" maxlength= name= "  Numbers">

5, can only input English letters and numbers, cannot input Chinese

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

6, can only enter numbers and English

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

7, only a maximum of two digits after the decimal point (numbers, Chinese can be entered), can not enter letters and operation symbols:

<input onkeypress="if (event.keycode<48 | | event.keycode>57) && event.keycode!=46 | | /\.\d\d$/.test (value)) Event.returnvalue=false">

8, only a maximum of two digits after the decimal point (numbers, letters, Chinese can be entered), you can enter the operation symbol:

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

Some small verification of JS

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: 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.