js form validation Guinness
1. Length
<script>
function test ()
(
if (document.abvalue.length> 50)
(
alert ( "Can not more than 50 characters!");
document.abfocus ();
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. Can only be characters
<input onkeyup="value="/oblog/value.replace(/[^\u4E00-\u9FA5]/g,'')">

3. "Can only be in English
<script language=javascript>
function onlyEng ()
(
if (! (event.keyCode> = 65 & & event.keyCode <= 90))
event.returnvalue = false;
)
</ script>

<input onkeydown="onlyEng();">

4. Can only be a figure
<script language=javascript>
function onlyNum ()
(
if (! ((event.keyCode> = 48 & & event.keyCode <= 57) | | (event.keyCode> = 96 & & event.keyCode <= 105)))
/ / Consider the small number keys on the keyboard
event.returnvalue = false;
)
</ script>

<input onkeydown="onlyNum();">
Either

<input type = "text" onkeypress = "if (event.keyCode <45 | | event.keyCode> 57) event.returnValue = false;" />
Or:
<input onkeyup = "if (event.keyCode! = 37 & & event.keyCode! = 39) value = value.replace (/ \ D / g ,'');" onbeforepaste =" clipboardData.setData ( 'text', clipboardData . getData ( 'text'). replace (/ \ D / g ,''))">
5. Are only English characters and numbers
<input onkeyup = "value =" / oblog / value.replace (/ [\ W] / g ,"'') "onbeforepaste =" clipboardData.setData ( 'text', clipboardData.getData ( 'text'). replace ( / [^ \ d] / g ,''))">

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

7. Shielding keyword (shielding here *** and ****)
<script language="javascript1.2">
function test () (
if ((abvalue.indexOf ("***") == 0) | | (abvalue.indexOf ("****") == 0)) (
alert (":)");
abfocus ();
return false;)
)
</ script>
<form name=a onsubmit="return test()">
<input type=text name=b>
<input type="submit" name="Submit" value="check">
</ form>

8. The same password twice
<FORM METHOD=POST ACTION="">
<input type="password">
<input type="password">
<input type="button" value="test">
</ 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 enough it cool shielding
oncontextmenu = "return false" ondragstart = "return false" onselectstart = "return false"
Increase in the body in

Two

2.1 Table of individual should not be empty

<script language="javascript">
<! --
function CheckForm ()
(
if (document.form.name.value.length == 0) (
alert ( "Please enter your name!");
document.form.name.focus ();
return false;
)
return true;
)
->
</ script>

Table 2.2 Comparison of the two individual values are the same

<script language="javascript">
<! --
function CheckForm ()
if (document.form.PWD.value! = document.form.PWD_Again.value) (
alert ( "You entered two different passwords! Please re-enter.");
document.ADDUser.PWD.focus ();
return false;
)
return true;
)
->
</ script>

2.3 Table only for a single figure and the "_", for telephone / bank account verification, the can be expanded to domain name registration, etc.

<script language="javascript">
<! --
function isNumber (String)
(
var Letters = "1234567890 -"; / / able to increase the input values
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 not legitimate!");
document.form.TEL.focus ();
return false;
)
return true;
)
->
</ script>

2.4 Table of individual input values / length limit

<script language="javascript">
<! --
function CheckForm ()
(
if (document.form.count.value> 100 | | document.form.count.value <1)
(
alert ( "Can not enter value greater than 100 less than zero!");
document.form.count.focus ();
return false;
)
if (document.form.MESSAGE.value.length <10)
(
alert ( "the importation of less than 10 characters!");
document.form.MESSAGE.focus ();
return false;
)
return true;
)
//-->
</ script>

2.5 Chinese / English / digital / e-mail address to determine the legality of

<SCRIPT LANGUAGE="javascript">
<! --

function isEnglish (name) / / Detect English values
(
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 values Detected
(
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 detection
(
if (! isEnglish (name))
return false;
i = name.indexOf ( "at");
j = name dot lastIndexOf ( "at");
if (i == -1)
return false;
if (i! = j)
return false;
if (i == name dot length)
return false;
return true;
)

function isNumber (name) / / Numerical Detected
(
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 e-mail is not legitimate!");
form.Email.focus ();
return false;
)
if (! isEnglish (form.name.value)) (
alert ( "English name is not legitimate!");
form.name.focus ();
return false;
)
if (! isChinese (form.cnname.value)) (
alert ( "Chinese name is not legitimate!");
form.cnname.focus ();
return false;
)
if (! isNumber (form.PublicZipCode.value)) (
alert ( "Zip code is not legitimate!");
form.PublicZipCode.focus ();
return false;
)
return true;
)
//-->
</ SCRIPT>

Table 2.6 qualified individual should not enter the characters

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

function contain (str, charset) / / string that 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 ( "entered the illegal characters");
document.form.NAME.focus ();
return false;
)
return true;
)
//-->
</ script>

1. Check whether the string section of the composition by the figure
---------------------------------------
<script language="Javascript"> <! --
function checkNum (str) (return str.match (/ \ D /) == null)
alert (checkNum ( "1232142141"))
alert (checkNum ( "123214214a1"))
/ / --></ Script>

2. How to determine whether characters are
---------------------------------------
if (/ [^ \ x00-\ xff] / g.test (s)) alert ( "contains Chinese characters");
else alert ( "all characters");

3. How to determine whether it contains any characters
---------------------------------------
if (escape (str). indexOf ( "% u ")!=- 1) alert (" contains Chinese characters ");
else alert ( "all characters");

4. E-mail format validation
---------------------------------------
/ / Function name: chkemail
/ / Function introduction: to check whether the Email Address
/ / Parameter Description: To check the string
/ / Return value: 0: No 1: Yes
function chkemail (a)
(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. Digital format verification
---------------------------------------
/ / Function name: fucCheckNUM
/ / Function introduction: to check whether the figure
/ / Parameter Description: To check the figures
/ / Return value: 1 for the figure, 0 is not a figure
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)
(
/ / Note characters have not figure
return 0;
)
)
/ / Note figure are
return 1;
)

6. Phone number format validation
---------------------------------------
/ / Function name: fucCheckTEL
/ / Function introduction: to check whether the phone number
/ / Parameter Description: To check the string
/ / Return value: 1 for are legitimate, 0 for non-legitimate
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)
(
/ / Note characters do not have legitimate
return 0;
)
)
/ / Account for the legal
return 1;
)

7. To determine whether the Chinese input function
---------------------------------------
function ischinese (s) (
var ret = true;
for (var i = 0; i <s.length; i + +)
ret = ret & & (s.charCodeAt (i)> = 10000);
return ret;
)

8. Integrated user input to determine the legality of the function
---------------------------------------
<script language="javascript">
/ / Restrict the importation of characters in the beginning of the median
/ / m are user input, n is to limit the number of bits
function issmall (m, n)
(
if ((m <n) && (m> 0))
(
return (false);
)
else
(return (true);)
)

9. To determine whether the password input line
---------------------------------------
function issame (str1, str2)
(
if (str1 == str2)
(return (true);)
else
(return (false);)
)

10. To determine whether the user name for the figure fell letters Line
---------------------------------------
function notchinese (str) (
var reg = / [^ A-Za-z0-9_] / g
if (reg.test (str)) (
return (false);
) else (
return (true);)
)

11. Form of general-purpose text field validation function
---------------------------------------
Role: Detect all the necessary non-empty input text, such as name, account number, e-mail address and so on.
The check is now only the text of the domain, if for the other form inside the domain object, you can determine the conditions for change.

Usage: Detected in the text domain to add language title. Characters are in the message you want to prompt to the user of the Chinese name of the field. To detect such as user name
html as follows <input name="txt_1" title="姓名">, of course, is best to use visualization tools such as dreamweaver what to edit domain.
If you want to figure the type of detection data, and then id unified domain sz.
javascript to determine the date type is too much trouble to make the date so there is no type checking procedure. you can add.

Procedures grass, simply provide a line of thought. Definitely! :)
Oh, yes, Ways function call: <form onsubmit = "return dovalidate ()">

function dovalidate ()
(
fm = document.forms [0] / / Detect only a form, if it is more than can be changed to determine the conditions for (i = 0; i <fm.length; i + +)
(
/ / Detect the conditions to determine, in accordance with different types can be modified if (fm [i]. TagName.toUpperCase ()==" INPUT "& & fm [i]. Type.toUpperCase ()==" TEXT" & & (fm [i]. title !=""))

if (fm [i]. value = "/ blog /="")//
(
str_warn1 = fm [i]. title + "should not be empty!";
alert (str_warn1);
fm [i]. focus ();
return false;
)
if (fm [i]. id.toUpperCase ()==" SZ ") / / (figure checksum
if (isNaN (fm [i]. value))
(Str_warn2 = fm [i]. Title + "wrong format";
alert (str_warn2);
fm [i]. focus ();
return false;
)
)
)
return true;
)

2> submit a verification form category

Table 2.1 individual should not be empty

<script language="javascript">
<! --
function CheckForm ()
(
if (document.form.name.value.length == 0) (
alert ( "Please enter your name!");
document.form.name.focus ();
return false;
)
return true;
)
->
</ script>

Table 2.2 Comparison of the two individual values are the same

<script language="javascript">
<! --
function CheckForm ()
if (document.form.PWD.value! = document.form.PWD_Again.value) (
alert ( "You entered two different passwords! Please re-enter.");
document.ADDUser.PWD.focus ();
return false;
)
return true;
)
->
</ script>

2.3 Table only for a single figure and the "_", for telephone / bank account verification, the can be expanded to domain name registration, etc.

<script language="javascript">
<! --
function isNumber (String)
(
var Letters = "1234567890 -"; / / able to increase the input values
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 not legitimate!");
document.form.TEL.focus ();
return false;
)
return true;
)
->
</ script>

2.4 Table of individual input values / length limit

<script language="javascript">
<! --
function CheckForm ()
(
if (document.form.count.value> 100 | | document.form.count.value <1)
(
alert ( "Can not enter value greater than 100 less than zero!");
document.form.count.focus ();
return false;
)
if (document.form.MESSAGE.value.length <10)
(
alert ( "the importation of less than 10 characters!");
document.form.MESSAGE.focus ();
return false;
)
return true;
)
//-->
</ script>

2.5 Chinese / English / digital / e-mail address to determine the legality of

<SCRIPT LANGUAGE="javascript">
<! --

function isEnglish (name) / / Detect English values
(
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 values Detected
(
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 detection
(
if (! isEnglish (name))
return false;
i = name.indexOf ( "at");
j = name dot lastIndexOf ( "at");
if (i == -1)
return false;
if (i! = j)
return false;
if (i == name dot length)
return false;
return true;
)

function isNumber (name) / / Numerical Detected
(
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 e-mail is not legitimate!");
form.Email.focus ();
return false;
)
if (! isEnglish (form.name.value)) (
alert ( "English name is not legitimate!");
form.name.focus ();
return false;
)
if (! isChinese (form.cnname.value)) (
alert ( "Chinese name is not legitimate!");
form.cnname.focus ();
return false;
)
if (! isNumber (form.PublicZipCode.value)) (
alert ( "Zip code is not legitimate!");
form.PublicZipCode.focus ();
return false;
)
return true;
)
//-->
</ SCRIPT>

Table 2.6 qualified individual should not enter the characters

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

function contain (str, charset) / / string that 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 ( "entered the illegal characters");
document.form.NAME.focus ();
return false;
)
return true;
)
//-->
</ script>