Js verification Overview

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. 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>

2.5 Determination of validity of Chinese/English/numbers/email addresses

<Script language = "javascript">
<! --

Function isEnglish (name) // english value detection
{
If (name. length = 0)
Return false;
For (I = 0; I <name. length; I ++ ){
If (name. charCodeAt (I)> 128)

Return false;
}
Return true;
}

Function isChinese (name) // Chinese value detection
{
If (name. length = 0)
Return false;
For (I = 0; I <name. length; I ++ ){
If (name. charCodeAt (I)> 128)
Return true;
}
Return false;
}

Function isMail (name) // E-mail value detection
{
If (! IsEnglish (name ))
Return false;
I = name. indexOf ("");
J = name dot lastIndexOf ("");
If (I =-1)
Return false;
If (I! = J)
Return false;
If (I = name dot length)
Return false;
Return true;
}

Function isNumber (name) // value detection
{
If (name. length = 0)
Return false;
For (I = 0; I <name. length; I ++ ){

If (name. charAt (I) <"0" | name. charAt (I)> "9 ")
Return false;
}
Return true;
}

Function CheckForm ()
{
If (! IsMail (form. Email. value )){
Alert ("your email is invalid! ");
Form. Email. focus ();
Return false;
}
If (! IsEnglish (form. name. value )){
Alert ("the English name is invalid! ");
Form. name. focus ();
Return false;
}
If (! IsChinese (form. cnname. value )){
Alert ("invalid Chinese name! ");
Form. cnname. focus ();
Return false;
}
If (! IsNumber (form. PublicZipCode. value )){
Alert ("the zip code is invalid! ");
Form. PublicZipCode. focus ();
Return false;
}
Return true;
}
// -->
</SCRIPT>

2.6 restrict characters that cannot be entered for Form Items

<Script language = "javascript">

<! --

Function contain (str, charset) // string contains the test function
{
Var I;
For (I = 0; I <charset. length; I ++)
If (str. indexOf (charset. charAt (I)> = 0)
Return true;
Return false;
}

Function CheckForm ()
{
If (contain (document. form. NAME. value, "% \ (\)> <") | (contain (document. form. MESSAGE. value, "% \ (\)> <")))
{
Alert ("illegal characters entered ");
Document. form. NAME. focus ();
Return false;
}
Return true;
}
// -->
</Script>

1. check whether a string is composed of digits.
---------------------------------------
<Script language = "Javascript"> <! --
Function checkNum (str) {return str. match (/\ D/) = null}
Alert (checkNum ("1232142141 "))
Alert (checkNum ("123214214a1 "))
// --> </Script>

2. How to determine whether it is a character
---------------------------------------
If (/[^ \ x00-\ xff]/g. test (s) alert ("containing Chinese characters ");
Else alert ("All characters ");

4. Email format Verification
---------------------------------------
// Function name: chkemail
// Function Description: Check whether the Email Address is used
// Parameter description: the string to be checked
// Return value: 0: Not 1: Yes
Function chkemail ()
{Var I = a. length;
Var temp = a. indexOf ('@');
Var tempd = a. indexOf ('.');
If (temp> 1 ){
If (I-temp)> 3 ){
If (I-tempd)> 0 ){
Return 1;
}

}
}
Return 0;
}

5. digit format Verification
---------------------------------------
// Function name: fucCheckNUM
// Function Description: Check whether it is a number
// Parameter description: number to be checked
// Return value: 1 is a number, and 0 is not a number
Function fucCheckNUM (NUM)
{
Var I, j, strTemp;
StrTemp = "0123456789 ";
If (NUM. length = 0)
Return 0
For (I = 0; I <NUM. length; I ++)
{
J = strTemp. indexOf (NUM. charAt (I ));

If (j =-1)
{
// It indicates that the character is not a number.
Return 0;
}
}
// The description is a number.
Return 1;
}

6. Phone Number Format Verification
---------------------------------------
// Function name: fucCheckTEL
// Function Description: Check whether the phone number is used
// Parameter description: the string to be checked
// Return value: 1 is valid, 0 is invalid
Function fucCheckTEL (TEL)
{
Var I, j, strTemp;
StrTemp = "0123456789 -()#";
For (I = 0; I <TEL. length; I ++)
{
J = strTemp. indexOf (TEL. charAt (I ));
If (j =-1)
{
// The specified character is invalid.
Return 0;
}
}
// Valid description
Return 1;
}

7. functions that determine whether the input is Chinese
---------------------------------------
Function ischinese (s ){

Var ret = true;
For (var I = 0; I <s. length; I ++)
Ret = ret & (s. charCodeAt (I) >= 10000 );
Return ret;
}

8. Comprehensive function for determining the legality of user input
---------------------------------------
<Script language = "javascript">
// Limit the start of the number of characters
// M is the user input, and n is the number of digits to be limited
Function issmall (m, n)
{
If (m <n) & (m> 0 ))
{
Return (false );
}
Else
{Return (true );}
}

9. Determine if the password is consistent
---------------------------------------
Function issame (str1, str2)
{
If (str1 = str2)
{Return (true );}
Else
{Return (false );}
}

10. Determine whether the user name is a hyphen (/) with numbers or letters
---------------------------------------
Function notchinese (str ){
Var reg =/[^ A-Za-z0-9 _]/g
If (reg. test (str )){

Return (false );
} Else {
Return (true );}
}

 

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.