Collection of JS form Verification control Code encyclopedia 1th/3 Page _ form effects

Source: Internet
Author: User
Tags domain name registration to domain
Keywords: JS verification form Daquan, with JS control form submission, JavaScript submission form:
Directory:
1:js string length limit, judge character length, JS limit input, limit not input, textarea length limit
2.:js Judging Chinese characters, judging whether Chinese characters, can only input Chinese characters
3:js judge whether to enter English, can only input English
4:js can only enter numbers, judge numbers, verify numbers, detect numbers, judge whether they are numbers, and enter only digits.
5: Only English characters and numbers can be entered
6:JS Email verification, JS judgment email, mailbox/mailbox format verification
7:js character filter, mask keyword
8:js Password authentication and judgment password
2.1:js is not empty, empty, or not object, judged empty, and judged not NULL
2.2: Compare the values of two table items
2.3: The form can only be numbers and "_",
2.4: Table Single input value/length limit
2.5: Chinese/English/digital/email address legality judgment
2.6: Limit the characters that a form item cannot enter
2.7 Form's self control
Universal Check function for 2.8:form text field

1. Length Limit
<script>
function test ()
{
if (DOCUMENT.A.B.VALUE.LENGTH&GT;50)
{
Alert ("Cannot exceed 50 characters!") ");
Document.a.b.focus ();
return false;
}
}
</script>
<form name=a onsubmit= "return Test ()" >
<textarea name= "B" cols= "wrap=" "VIRTUAL" rows= "6" ></textarea>
<input type= "Submit" name= "Submit" value= "Check" >
</form>

2. Can only be Chinese characters
<input onkeyup= "value="/oblog/value.replace (/[^\u4e00-\u9fa5]/g, ') ">

3. "Can only be English
<script language=javascript>
function Onlyeng ()
{
if (!) ( EVENT.KEYCODE&GT;=65&AMP;&AMP;EVENT.KEYCODE&LT;=90))
Event.returnvalue=false;
}
</script>

<input onkeydown= "Onlyeng ();" >

4. Only the numbers
<script language=javascript>
function Onlynum ()
{
if (!) ( (event.keycode>=48&&event.keycode<=57) | | (event.keycode>=96&&event.keycode<=105)))
Consider the number keys on the keypad
Event.returnvalue=false;
}
</script>

<input onkeydown= "Onlynum ();" >

5. 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 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 shield * * * * and * * * *)
<script language= "javascript1.2" >
function Test () {
if ((A.b.value.indexof ("* *") = = 0) | | (A.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. Two times input password is 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>
That's enough,:).
Shielding right button is cool
Oncontextmenu= ' return false ' ondragstart= ' return false ' onselectstart= ' return false '
Added to the body.


Two

2.1 Form items cannot 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>

2.2 Compare the values of two table items

<script language= "JavaScript" >
<!--
function Checkform ()
if (Document.form.PWD.value!= document.form.PWD_Again.value) {
Alert ("The password you entered two times is different!") Please re-enter. ");
Document. ADDUser.PWD.focus ();
return false;
}
return true;
}
-->
</script>

2.3 Form items can only be numbers and "_" for phone/bank account verification, can be extended to domain name registration, etc.

<script language= "JavaScript" >
<!--
function Isnumber (String)
{
var letters = "1234567890-"; You can add your own input value
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 legal!") ");
Document.form.TEL.focus ();
return false;
}
return true;
}
-->
</script>


2.4 Table Single 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 0 or greater than 100!");
Document.form.count.focus ();
return false;
}
if (document.form.message.value.length<10)
{
Alert ("Input text is less than 10!");
Document.form.MESSAGE.focus ();
return false;
}
return true;
}
-->
</script>
current 1/3 page   1 23 Next read the full text

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.