Keywords: js verification form Daquan, use JS to control form submission, javascript to submit form:
Directory:
1: js string length limit, determination character length, js restriction input, restriction not input, textarea length limit
2.: js judges Chinese characters, determines whether Chinese characters are needed, and can only input Chinese Characters
3: js determines whether the input is in English. Only English can be entered.
4: javascript can only enter numbers, determine numbers, verify numbers, detect numbers, determine whether they are numbers, and only enter numbers
5: Only English characters and numbers can be entered
6: js email verification, js judgment email, mailbox/mailbox format Verification
7: js character filtering, blocking keywords
8: js password verification and password Determination
2.1: js is not empty, empty, or not an object. The judgment is empty. The judgment is not empty.
2.2: compare whether the values of two form items are the same
2.3: The form can only contain numbers and "_",
2.4: Number/length limit entered for Form Items
2.5: Chinese/English/number/email address legality judgment
2.6: Restrict characters that cannot be entered for Form Items
2.7 form User Control
2.8: Common verification functions for form text fields
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>
Enough :)
Blocking right-click is cool
Oncontextmenu = "return false" ondragstart = "return false" onselectstart = "return false"
Add to body
II
2.1 Form items cannot be blank
<Script language = "javascript">
<! --
Function CheckForm ()
{
If (document. form. name. value. length = 0 ){
Alert ("enter your name! ");
Document. form. name. focus ();
Return false;
}
Return true;
}
-->
</Script>
2.2 compare whether the values of the two form items are the same
<Script language = "javascript">
<! --
Function CheckForm ()
If (document. form. PWD. value! = Document. form. PWD_Again.value ){
Alert ("the password you entered twice is different! Enter again .");
Document. ADDUser. PWD. focus ();
Return false;
}
Return true;
}
-->
</Script>
2.3 form items can only be numbers and "_", used for phone/Bank Account Verification, and can be extended to domain name registration.
<Script language = "javascript">
<! --
Function isNumber (String)
{
Var Letters = "1234567890-"; // you can add input values by yourself.
Var I;
Var c;
If (String. charAt (0) = '-')
Return false;
If (String. charAt (String. length-1) = '-')
Return false;
For (I = 0; I <String. length; I ++)
{
C = String. charAt (I );
If (Letters. indexOf (c) <0)
Return false;
}
Return true;
}
Function CheckForm ()
{
If (! IsNumber (document. form. TEL. value )){
Alert ("your phone number is invalid! ");
Document. form. TEL. focus ();
Return false;
}
Return true;
}
-->
</Script>
2.4 form entry input value/length limit
<Script language = "javascript">
<! --
Function CheckForm ()
{
If (document. form. count. value> 100 | document. form. count. value <1)
{
Alert ("the input value cannot be less than zero or greater than 100! ");
Document. form. count. focus ();
Return false;
}
If (document. form. MESSAGE. value. length <10)
{
Alert ("the input text is less than 10! ");
Document. form. MESSAGE. focus ();
Return false;
}
Return true;
}
// -->
</Script>