Page 1/3 of the Javascript form verification control code list

Source: Internet
Author: User
Tags domain name registration to domain

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. blocking keywords (here, shielding ***** and *****)




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

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.