Add: JS Verify Radio is selected
<script language= "JavaScript" >
function Checkform (obj)
{
for (i=0;i<obj.oo.length;i++)
if (obj.oo[i].checked==true) return true;
Alert ("Please select")
return false;
}
</script>
<form id= "Form1" Name= "Form1" method= "Post" action= "" onsubmit= "return Checkform (This)" >
<input type= "Radio" Name= "oo" value= "RadioButton"/>
<input type= "Radio" Name= "oo" value= "RadioButton"/>
<input type= "Submit" name= "Submit" value= " submission "/>
</form>
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= "+" 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 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 number
<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
<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. Block Keywords (shield * * * and * * * * here)
<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 the same password is entered
<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.
Shield Right button is cool
Oncontextmenu= "return false" ondragstart= "return false" onselectstart= "return False"
Add it to the body.
Two
2.1 The form item 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 two table items for the same value
<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 numeric and "_" for phone/bank account verification, can be extended to domain name registration, etc.
<script language= "JavaScript" >
<!--
function Isnumber (String)
{
var Letters = "1234567890-"; can increase the input value by itself
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 Item input value/length limit
<script language= "JavaScript" >
<!--
function Checkform ()
{
if (Document.form.count.value > 100 | | Document.form.count.value < 1)
{
Alert ("Input value cannot be less than 0 greater than 100!");
Document.form.count.focus ();
return false;
}
if (document.form.message.value.length<10)
{
Alert ("Input text less than 10!");
Document.form.MESSAGE.focus ();
return false;
}
return true;
}
-
</script>
2.5 Chinese/English/digital/e-mail address legality judgment
<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 ("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)//numeric 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 illegal!") ");
Form. Email.focus ();
return false;
}
if (! Isenglish (Form.name.value)) {
Alert ("English name is not legal!") ");
Form.name.focus ();
return false;
}
if (! Ischinese (Form.cnname.value)) {
Alert ("Chinese name is not legal!") ");
Form.cnname.focus ();
return false;
}
if (! Isnumber (form. Publiczipcode.value)) {
Alert ("ZIP code is illegal! ");
Form. Publiczipcode.focus ();
return false;
}
return true;
}
-
</SCRIPT>
2.6 Characters that limit the entry of a form item
<script language= "JavaScript" >
<!--
function contain (Str,charset)//string contains 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 character entered");
Document.form.NAME.focus ();
return false;
}
return true;
}
-
</script>
JS Validation Form JS commit validation class