Keywords: js verification form collection, use JS to control form submission, javascript submit form:
Table of contents:
1: js string length limit, judge character length, js restrict input, limit inability to input, textarea length limit
2.: js determines Chinese characters, determines whether Chinese characters are, and can only enter Chinese characters
3: JS determine whether to enter English, only English can be entered
4: js can only enter numbers, judge numbers, verify numbers, detect numbers, judge 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/email format verification
7: js character filtering, block keywords
8: js password verification, password judgment
2.1: js is not empty, is empty or is not an object, judged as empty, judged as not empty
2.2: Compare whether the values of two form items are the same
2.3: The form can only be number and "_",
2.4: Type entry value/length limit
2.5: Judgment of legality of Chinese/English/Number/Email Address
2.6: Characters that cannot be entered in a limited form item
2.7 Self-contained control of forms
2.8: General check function for form text field
1. Length limit
<script>
function test()
{
if(>50)
{
alert("can't exceed 50 characters!");
();
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. It can only be Chinese characters
<input onkeyup="value="/oblog/(/[^\u4E00-\u9FA5]/g,'')">
3. "It can only be in English
<script language=javascript>
function onlyEng()
{
if(!(>=65&&<=90))
=false;
}
</script>
<input onkeydown="onlyEng();">
4. It can only be a number
<script language=javascript>
function onlyNum()
{
if(!((>=48&&<=57)||(>=96&&<=105)))
//Consider the numeric keys on the keyboard
=false;
}
</script>
<input onkeydown="onlyNum();">
5. It can only be English characters and numbers
<input onkeyup="value="/oblog/(/[\W]/g,"'') "onbeforepaste="('text',('text').replace(/[^\d]/g,''))">
6. Verify the fuel tank format
<SCRIPT LANGUAGE=javascript RUNAT=Server>
function isEmail(strEmail) {
if ((/^\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()>
7. Block keywords (block *** and **** here)
<script language="javascript1.2">
function test() {
if(( ("***") == 0)||( ("****") == 0)){
alert(":)");
();
return false;}
}
</script>
<form name=a onsubmit="return test()">
<input type=text name=b>
<input type="submit" name="Submit" value="check">
</form>
8. Is the password the same twice
<FORM METHOD=POST ACTION="">
<input type="password" >
<input type="password" >
<input type="button" value="test" onclick="check()">
</FORM>
<script>
function check()
{
with(){
if(!=)
{
alert("false")
= "";
= "";
}
else [0].submit();
}
}
</script>
Enough :)
Right-blocking is cool
oncontextmenu="return false" ondragstart="return false" onselectstart="return false"
Added in body
two
2.1 The form item cannot be empty
<script language="javascript">
<!--
function CheckForm()
{
if ( == 0) {
alert("Please enter your name!");
();
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 ( != .PWD_Again.value) {
alert("The password you entered twice is different! Please re-enter.");
();
return false;
}
return true;
}
-->
</script>
2.3 The form item can only be number and "_", used for phone/bank account verification, can be extended to domain name registration, etc.
<script language="javascript">
<!--
function isNumber(String)
{
var Letters = "1234567890-"; //You can increase the input value yourself
var i;
var c;
if(( 0 )=='-')
return false;
if( ( - 1 ) == '-' )
return false;
for( i = 0; i < ; i ++ )
{
c = ( i );
if (( c ) < 0)
return false;
}
return true;
}
function CheckForm()
{
if(! isNumber()) {
alert("Your phone number is illegal!");
();
return false;
}
return true;
}
-->
</script>
2.4 The input value/length limit of form items
<script language="javascript">
<!--
function CheckForm()
{
if ( > 100 || < 1)
{
alert("The input value cannot be less than zero or greater than 100!");
();
return false;
}
if (<10)
{
alert("Input text is less than 10!");
();
return false;
}
return true;
}
//-->
</script>
Table of contents:
1: js string length limit, judge character length, js restrict input, limit inability to input, textarea length limit
2.: js determines Chinese characters, determines whether Chinese characters are, and can only enter Chinese characters
3: JS determine whether to enter English, only English can be entered
4: js can only enter numbers, judge numbers, verify numbers, detect numbers, judge 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/email format verification
7: js character filtering, block keywords
8: js password verification, password judgment
2.1: js is not empty, is empty or is not an object, judged as empty, judged as not empty
2.2: Compare whether the values of two form items are the same
2.3: The form can only be number and "_",
2.4: Type entry value/length limit
2.5: Judgment of legality of Chinese/English/Number/Email Address
2.6: Characters that cannot be entered in a limited form item
2.7 Self-contained control of forms
2.8: General check function for form text field
1. Length limit
<script>
function test()
{
if(>50)
{
alert("can't exceed 50 characters!");
();
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. It can only be Chinese characters
<input onkeyup="value="/oblog/(/[^\u4E00-\u9FA5]/g,'')">
3. "It can only be in English
<script language=javascript>
function onlyEng()
{
if(!(>=65&&<=90))
=false;
}
</script>
<input onkeydown="onlyEng();">
4. It can only be a number
<script language=javascript>
function onlyNum()
{
if(!((>=48&&<=57)||(>=96&&<=105)))
//Consider the numeric keys on the keyboard
=false;
}
</script>
<input onkeydown="onlyNum();">
5. It can only be English characters and numbers
<input onkeyup="value="/oblog/(/[\W]/g,"'') "onbeforepaste="('text',('text').replace(/[^\d]/g,''))">
6. Verify the fuel tank format
<SCRIPT LANGUAGE=javascript RUNAT=Server>
function isEmail(strEmail) {
if ((/^\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()>
7. Block keywords (block *** and **** here)
<script language="javascript1.2">
function test() {
if(( ("***") == 0)||( ("****") == 0)){
alert(":)");
();
return false;}
}
</script>
<form name=a onsubmit="return test()">
<input type=text name=b>
<input type="submit" name="Submit" value="check">
</form>
8. Is the password the same twice
<FORM METHOD=POST ACTION="">
<input type="password" >
<input type="password" >
<input type="button" value="test" onclick="check()">
</FORM>
<script>
function check()
{
with(){
if(!=)
{
alert("false")
= "";
= "";
}
else [0].submit();
}
}
</script>
Enough :)
Right-blocking is cool
oncontextmenu="return false" ondragstart="return false" onselectstart="return false"
Added in body
two
2.1 The form item cannot be empty
<script language="javascript">
<!--
function CheckForm()
{
if ( == 0) {
alert("Please enter your name!");
();
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 ( != .PWD_Again.value) {
alert("The password you entered twice is different! Please re-enter.");
();
return false;
}
return true;
}
-->
</script>
2.3 The form item can only be number and "_", used for phone/bank account verification, can be extended to domain name registration, etc.
<script language="javascript">
<!--
function isNumber(String)
{
var Letters = "1234567890-"; //You can increase the input value yourself
var i;
var c;
if(( 0 )=='-')
return false;
if( ( - 1 ) == '-' )
return false;
for( i = 0; i < ; i ++ )
{
c = ( i );
if (( c ) < 0)
return false;
}
return true;
}
function CheckForm()
{
if(! isNumber()) {
alert("Your phone number is illegal!");
();
return false;
}
return true;
}
-->
</script>
2.4 The input value/length limit of form items
<script language="javascript">
<!--
function CheckForm()
{
if ( > 100 || < 1)
{
alert("The input value cannot be less than zero or greater than 100!");
();
return false;
}
if (<10)
{
alert("Input text is less than 10!");
();
return false;
}
return true;
}
//-->
</script>
123Next pageRead the full text