JavaScript common various authentication code encyclopedia (1/5)

Source: Internet
Author: User

1. Length Limit

The code is as follows Copy Code

<script>

function test ()

{

if (DOCUMENT.A.B.VALUE.LENGTH>50)

{

Alert ("Cannot exceed 50 characters!") ");

Document.a.b.focus ();

return false;

}

}

</script>

<form name=a onsubmit= "return Test ()" >

<textarea name= "B" cols= "wrap=" "VIRTUAL" rows= "6" ></textarea>

<input type= "Submit" name= "Submit" value= "Check" >

</form>


2. Can only be Chinese characters

The code is as follows Copy Code
<input onkeyup= "value="/oblog/value.replace (/[^u4e00-u9fa5]/g, ') ">

3. can only be English

The code is as follows Copy Code

<script language= "JavaScript" >

function Onlyeng ()

{

if (!) ( EVENT.KEYCODE>=65&&EVENT.KEYCODE<=90))

Event.returnvalue=false;

}

</script>


<input onkeydown= "Onlyeng ();" >

4. Only the numbers

The code is as follows Copy Code

<script language=javascript>

function Onlynum ()

{

if (!) ( (event.keycode>=48&&event.keycode<=57) | | (event.keycode>=96&&event.keycode<=105)))

Consider the number keys on the keypad

Event.returnvalue=false;

}

</script>
<input onkeydown= "Onlynum ();" >

5. Only English characters and numbers

The code is as follows Copy Code

<input onkeyup= "value="/oblog/value.replace (/[w]/g, "')"

Onbeforepaste= "Clipboarddata.setdata" (' Text ', Clipboarddata.getdata (' text '). Replace (/[^d]/g, ') ">

6. Verify the fuel tank format

The code is as follows Copy Code

<script Language=javascript runat=server>

function Isemail (stremail) {

if (/^w+ (-w+) | (stremail.search) | (. w+)) *@[a-za-z0-9]+ ((. | -) [a-za-z0-9]+] *. [a-za-z0-9]+$/)!=-1)

return true;

Else

Alert ("Oh");

}

</SCRIPT>


<input type=text onblur=isemail (this.value) >

. Shielding Keywords (here block * * * * and * * * *)

The code is as follows Copy Code

<script language= "javascript1.2" >

function Test () {

if ((A.b.value.indexof ("* *") = = 0) | | (A.b.value.indexof ("* * *") = = 0)) {

Alert (":)");

A.b.focus ();

return false;}

}

</script>


<form name=a onsubmit= "return Test ()" >

<input Type=text name=b>

<input type= "Submit" name= "Submit" value= "Check" >

</form>

8. Two times input password is the same

The code is as follows Copy Code

<form method=post action= "" >

<input type= "Password" id= "INPUT1" >

<input type= "Password" id= "Input2" >

<input type= "button" value= "Test" onclick= "Check ()" >

</FORM>

<script>

function Check ()

{

With (document.all) {

if (Input1.value!=input2.value)

{

Alert ("false")

Input1.value = "";

Input2.value = "";

}

else Document.forms[0].submit ();

}

}

</script>

That's enough, right now, that's cool.

The code is as follows Copy Code
Oncontextmenu= ' return false ' ondragstart= ' return false ' onselectstart= ' return false '

Added to the body.


Home 1 2 3 4 5 last

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.