JS Various validation text box input content format

Source: Internet
Author: User

the input box cannot be empty
<input onblur= "if (This.value.replace (/^ +| +$/g, ') = =") alert (' cannot be empty! ') " >

Only English and numbers can be entered
<input onblur= "if (/[^0-9a-za-z]/g.test (value)) alert (' wrong ') ' >
<input onkeyup= "Value=value.replace (/[^0-9a-za-z]/g, ')"/>
<input type= "text" onkeyup= "Value=value.replace (/[^\a-\z\a-\z0-9]/g, ')" >

The judging character consists of a letter and a number, an underscore, and a dot. And only the underscore and the letter can begin
/^ ([A-za-z_]{1}) ([\w]*) $/g.test (str)

Only numbers can be entered
<input name= "text" type= "text" id= "NewPage" onkeyup= "Value=value.replace (/\d/g, ')" onafterpaste= "value= Value.replace (/\d/g, ') ">

You can only enter Chinese
<input type= "text" onkeyup= "Value=value.replace (/[^\u4e00-\u9fa5]/g, ')" >

Can only be entered in English
<input type= "text" onkeyup= "Value=value.replace (/[^\a-\z\a-\z]/g, ')" >
<input type= "text" onkeyup= "Value=value.replace (/[^a-za-z]/g, ')" >

You can only enter Chinese, English, numbers, @ symbols, and. Symbols
<input type= "text" onkeyup= "Value=value.replace (/[^\a-\z\a-\z0-9\u4e00-\u9fa5\@\.] /g, ') ' >

Only English is allowed and cannot be pasted or pop-up menu
<input type= "text" onkeyup= "Value=value.replace (/[^\a-\z\a-\z]/g, ')" onkeydown= "Fnckeystop (event)" Onpaste= " return false "OnContextMenu =" return false "/>

Only numbers and dot numbers can be entered (note: in [^\d\.] D cannot be written in uppercase D, otherwise it becomes all characters except the number.
<input name= "Price" type= "text" size= "8" maxlength= "8" onkeyup= "Value=value.replace (/[^\d\.] /g, ') ' >

All in all: First enter onkeyup= "Value=value.replace (/[^\x]/g,") in <input> and then X in (/[\x]/g, ") to the code you want to enter.

English : u4e00-u9fa5
numbers : D, 0-9
English : A-Z, A-Z
Other symbols @, dots, or other symbols. Can also be multiple, with \ Separated on the line.
For example:
Add symbols in Chinese, English, and digital plus @ symbols: \a-\z\a-\z0-9\u4e00-\u9fa5\@\.

If you want to not right-click in the text box pop-up menu and can not paste into the copied information, you will enter the <input> onkeydown= "Fnckeystop (event)" onpaste= "return false" OnContextMenu = "return false;"

JS Various validation text box input content format

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.