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.