1. length limit
<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 = "40" Wrap = "virtual" rows = "6"> </textarea>
<Input type = "Submit" name = "Submit" value = "check">
</Form>
2. Only Chinese characters are allowed
<Input onkeyup = "value ="/oblog/value. Replace (/[^/u4e00-/u9fa5]/g, '')">
3. "English only
<Script language = JavaScript>
Function onlyeng ()
{
If (! (Event. keycode> = 65 & event. keycode <= 90 ))
Event. returnvalue = false;
}
</SCRIPT>
<Input onkeydown = "onlyeng ();">
4. Only numbers are allowed.
<Script language = JavaScript>
Function onlynum ()
{
If (! (Event. keycode> = 48 & event. keycode <= 57) | (event. keycode> = 96 & event. keycode <= 105 )))
// Consider the numeric keys on the keypad
Event. returnvalue = false;
}
</SCRIPT>
<Input onkeydown = "onlynum ();">
5. Only English characters and numbers are allowed.
<Input onkeyup = "value ="/oblog/value. replace (/[/W]/g, "'') "onbeforepaste =" clipboardData. setdata ('text', clipboardData. getdata ('text '). replace (/[^/d]/g, '')">
6. Verify the fuel tank format
<Script language = JavaScript runat = Server>
Function isemail (stremail ){
If (stremail. search (/^/W + (-/W +) | (/. /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)>
7. Shielding keywords (here, shielding ***** and ****)
<Script language = "javascript1.2">
Function Test (){
If (. b. value. indexof ("***") = 0) | (. 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. Whether the two passwords are the same
<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>
Right-click shielding
Oncontextmenu = "Return false" ondragstart = "Return false" onselectstart = "Return false"
Add to Body