Summary of JavaScript verification knowledge code

Source: Internet
Author: User
This article mainly introduces the knowledge of JavaScript verification. It has good reference value. Next, let's take a look at it. This article mainly introduces the knowledge of JavaScript verification. It has good reference value. Let's take a look at it with the small Editor.

Javascript can only enter regular expressions such as numbers, numbers, and letters.

1. Only numeric code can be entered in the text box (decimal point cannot be entered)

 

2. Only numbers can be entered, and decimal points can be entered.

 

3. Number and decimal point method 2

 

4. Only letters and Chinese characters can be entered

 

5. Only English letters and numbers are allowed. Chinese characters are not allowed.

 

6. Only numbers and English chun numbers can be entered.

 

7. After the decimal point, you can enter a maximum of two digits (numbers and Chinese characters). You cannot enter letters or operator numbers:

 

8. A maximum of two digits (numbers, letters, and Chinese characters) can be entered after the decimal point. You can enter the operator number:

 

Special characters are prohibited:

onKeyPress="if(event.keyCode < 45 || event.keyCode > 57 ) event.returnValue = false;"

Only Chinese characters can be entered:

 

Style = "ime-mode: disabled" prohibiting Chinese Character Input Methods

Only numbers can be entered:

 

Only English letters and numbers can be entered:

 

The control input box can only contain text, numbers, or special characters.

The following characters cannot be entered: (such as ^)

</Pre>

Enter spaces only

onkeyup="value=value.replace(//s/g,'')"onkeydown="if(event.keyCode==32) return false"

Only Chinese and English characters can be entered:

onkeyup="value=value.replace(/[^/a-zA-Z/u4E00-/u9FA5]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^/a-zA-Z/u4E00-/u9FA5]/g,''))"

Special characters and spaces are not allowed:

Cannot be blank

A judgment character consists of letters, numbers, underscores, and periods. It must start with an underscore or letter.

/^([a-zA-z_]{1})([\w]*)$/g.test(str)

Only numbers can be entered

Only Chinese characters can be entered

Only English can be entered

Only Chinese characters, English letters, numbers, @ symbols, and. symbols can be entered.

You can only enter English letters, and the paste menu cannot be displayed.

Only numbers and periods can be entered (Note: d in [^ \ d \.] cannot be written as uppercase D, otherwise it will become all characters except numbers)

All in all:Enter onkeyup = "value = value. replace (/[^ \ X]/g, '')" and then in (/[\ X]/g ,'') replace X in with the code you want to enter.

English: u4E00-u9FA5

Number: d, 0-9

English: a-z, A-Z

Other symbols @, point, or other symbols. You can also use multiple symbols and separate them.

For example:

English and numbers plus the @ symbol plus some symbols: \ a-\ z \ A-\ Z0-9 \ u4E00-\ u9FA5 \@\.

If you do not want to right-click the menu in the text box or paste the copied information inEnter onKeyDown = "fncKeyStop (event)" onpaste = "return false" oncontextmenu = "return false ;"

First, only numbers and decimal points are allowed.

Second, the judgment is more detailed, and even 22 .. 2 is not counted as a number.

Script function check () {if (isNaN (tt. value) {alert ("invalid character! "); Tt. value =" ";}} script

Third, only integers are allowed. In fact, some restrictions can be made based on article 3.

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.