search
HomeWeb Front-endJS TutorialJS form validation encyclopedia_form effects

1. Only numbers and English can be entered:

2. Only numbers can be entered:
< ;input onkeyup="value=value.replace(/[^/d]/g,'') " onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^/ d]/g,''))" ID="Text2" NAME="Text2">
3. Only full-width input is possible:

4. Only Chinese characters can be input:

--------------------------------------------- ----------------------------------------
Verify illegal characters, sql
function vdf()
{
var i,j,name,value,message,length,type,a=vdf.arguments,cb_name;
for (i=0; i{
if (a[i].indexOf('#')!=-1)
{
name=fob(a[i]. substr(0,a[i].indexOf('#')));
cb_name=fob(a[i].substr((a[i].indexOf('#') 1),a[i ].length));
}
else
{
name=fob(a[i]); // Control name
}
message=a[i 1]; // Prompt message
type=a[i 2]; // Type
if (type!="r_time")
{
value=name.value.replace(/ /g, " "); // Control value
}
else
{
value=name.value;
}
}
---------- -------------------------------------------------- ------------------
// =============== Determine whether the check box is selected====== =========== //
if (type=="r_cb")
{
e=document.forms(0).elements;
var flag=false ;
for (i=0;i{
if (e[i]!=cb_name)
{
if (e[i].checked ==true)
{
flag=true;
break;
}
}
if (i==e.length-1)
{
break ;
}
}
if (flag==false)
{
alert(message "!/n"); //The prompt that appears when it is empty
return false;
}
}
// =============== Determine whether the drop-down box is selected ================ / /
if (type=="r_sl")
{
if (name.selected==false)
{
alert(message "!/n"); //Empty The prompt that appears when
return false;
}
}
// =============== Judgment that it cannot be empty ======= ========= //
if (type=="r")
{
if (value=="") // Determine whether it is empty
{
alert(message "!/n"); //The prompt that appears when it is empty
name.focus();
name.select();
return false;
}
}
// =============== Cannot be empty, but does not get focus ================ //
if (type=="o_r")
{
if (value=="") // Determine whether it is empty
{
alert(message "!/n"); / / Prompt that appears when it is empty
return false;
}
}
// =============== Only Chinese can be entered ===== =========== //
if (type=="r_china")
{
if (value.search(/^[/u4e00-/u9fa5] $/) ==-1)
{
alert(message "!/n"); // The judgment cannot be empty
name.focus();
name.select();
return false;
}
}
// =============== Cannot be empty, must be a number or character. ========== ====== //
if (type=="r_num_char")
{
if (value=="")
{
alert(message "!/n" ); //The prompt that appears when it is empty
name.focus();
name.select();
return false;
}
if (value.search(/^[ 0-9a-zA-Z] $/)==-1)
{
alert(message "!/n"); //The prompt that appears when it is empty
name.focus();
name.select();
return false;
}
}
// =============== Can be empty, not empty When, fill in the number ================ //
if (type=="num")
{
if (value.search(/^[ 0-9] $/)==-1 && value!="")
{
alert(message "!/n"); // The judgment cannot be empty
name.focus();
name.select();
return false;
}
}
// =============== cannot be empty, must be a number Judgment ================ //
if (type=="r_num")
{
if (value=="")
{
alert(message "!/n");
name.focus();
name.select();
return false;
}
if (value.search( /^[0-9] $/)==-1)
{
alert(message "!/n"); // The judgment cannot be empty
name.focus();
name.select();
return false;
}
}
// ===============Must enter a number less than n==== ============ //
if (type.indexOf("r_num{
length=type.substring((type.indexOf ('if (value=="") // Prompt for empty
{
alert(message "!/n");
name.focus();
name.select();
return false;
}
if (value.search(/^[0-9 ] $/)==-1) // Not made of numbers
{
alert(message "!/n");
name.focus();
name.select() ;
return false;
}
if (value.length>length) // Limit the length of the number
{
alert(message "!/n");
name.focus();
name.select();
return false;
}
}
// ===============Must enter a number greater than n================ //
if (type .indexOf("r_num>")!=-1)
{
length=type.substring((type.indexOf('>') 1),type.length); // Get the back of rnif (value=="") // Prompt for empty
{
alert(message "!/n");
name.focus();
name .select();
return false;
}
if (value.search(/^[0-9] $/)==-1) // Not made of numbers
{
alert(message "!/n");
name.focus();
name.select();
return false;
}
if (value.length{
alert(message "!/n");
name.focus();
name.select();
return false ;
}
}
// ===============Must enter a number between a-b ============= === //
if (type.indexOf("r_num#")!=-1)
{
length=type.substr((type.indexOf('>' ) 1),type.length);
length=length.substr(0,length.lastIndexOf("-"));
length1=type.substring((type.indexOf('-') 1) ,type.length) // Get the number after rnif (value=="") // Prompt for empty
{
alert(message "!/n");
name.focus();
name.select();
return false;
}
if (value.search(/^[0-9] $/)==-1) // Not a reminder made of numbers
{
alert(message "!/n");
name.focus();
name.select();
return false;
}
if (value.lengthlength1) // Limit the length of the number
{
alert(message "!/n");
name. focus();
name.select();
return false;
}
}
// =============== cannot be empty , must be of float type================ //
if (type=="r_float")
{
if (value=="")
{
alert(message "!/n");
name.focus();
name.select();
return false;
}
if ( value.search(/^[0-9] $/)!=-1 || value.search(/^([0-9] )|([0-9] /.[0-9]*)| ([0-9]*/.[0-9] )$/)!=-1)
{
return true;
}
else
{
alert( message "!/n"); // The judgment cannot be empty
name.focus();
name.select();
return false;
}
}
/ / =============== To determine the email, you do not have to enter ================ //
if (type.indexOf(" email")!=-1)
{
if (name.value!="")
{
if (value.search(/^[_/.a-z0-9] @[a-z0-9] [/.][a-z0-9]{2,}$/i)==-1)
{
alert(message "!/n");
name.focus();
name.select();
return false;
}
}
}
// ========== =====To determine email, be sure to enter================ //
if (type.indexOf("r_email")!=-1)
{
if (name.value=="")
{
alert(message "!/n");
name.focus();
name.select();
return false;
}
if (value.search(/^[_/.a-z0-9] @[a-z0-9] [/.][a-z0-9]{2 ,}$/i)==-1)
{
alert(message "!/n");
name.focus();
name.select();
return false;
}
}
// =============== Determine the date, such as 2000-12-20============ ===== //
if (type=="r_date")
{
flag=true;
getdate=value;
if (getdate.search(/^[0 -9]{4}-(0[1-9]|[1-9]|1[0-2])-((0[1-9]|[1-9])|1[0-9 ]|2[0-9]|3[0-1])$/)==-1) // Correct when judging the input format
{
flag=false;
}
else
{
var year=getdate.substr(0,getdate.indexOf('-')) // Get the year
// The following operation is to get the month
var transition_month=getdate.substr(0, getdate.lastIndexOf('-'));
var month=transition_month.substr(transition_month.lastIndexOf('-') 1,transition_month.length);
if (month.indexOf('0')== 0)
{
month=month.substr(1,month.length);
}
// The following operation is to obtain the date
var day=getdate.substr(getdate.lastIndexOf(' -') 1,getdate.length);
if (day.indexOf('0')==0)
{
day=day.substr(1,day.length);
}
//alert(month);
//alert(day)
//return false;
if ((month==4 || month==6 || month==9 || month==11) && (day>30)) // The dates in 4, 6, 9 and 11 months cannot exceed 30
{
flag=false;
}
if (month= =2) // Determine February
{
if (LeapYear(year))
{
if (day>29 || day}
else
{
if (day>28 || day}
}
else
{
flag=true ;
}
}
if (flag==false)
{
alert(message "!/n"); //The prompt that appears when it is empty
name.focus ();
name.select();
return false;
}
}
1. Length limit
<script> <BR>function test() <BR> { <BR>if(document.a.b.value.length>50) <BR>{ <BR>alert("Cannot exceed 50 characters!"); <BR>document.a.b.focus(); <BR>return false; <BR>} <BR>} <BR></script>





2. Can only be Chinese characters

3." It can only be in English


4. Can only be numbers


7. Block keywords (*** and **** are blocked here)





8. Twice Are the input passwords the same?

"input2">


<script> <BR>function check () <BR>{ <BR>with(document.all){ <BR>if(input1.value!=input2.value) <BR>{ <BR>alert("false") <BR>input1.value = ""; <BR>input2.value = ""; <BR>} <BR>else document.forms[0].submit(); <BR>} <BR>} <BR></script>
That’s enough :)
It’s cool to block the right click
oncontextmenu="return false" ondragstart="return false" onselectstart="return false"
Add to body
Two
2.1 Table Single item cannot be empty

2.2 Compare whether the values ​​of two form items are the same

2.3 Form items can only be numbers and "_", which are used for phone/bank account verification and can be extended to domain name registration, etc.
> ;
2.4 Form item input value/length limit
> ;
2.5 Chinese/English/numeric/email address validity judgment
> ;
2.6 Limit the characters that cannot be entered in form items

1. Check whether a string consists entirely of numbers
---------------------------------- ----

2. How to determine whether it is a character
---- ----------------------------------
if (/[^/x00-/xff]/ g.test(s)) alert("Contains Chinese characters");
else alert("All characters");
3. How to judge whether it contains Chinese characters
--------- -------------------------------
if (escape(str).indexOf("%u")!=- 1) alert("contains Chinese characters");
else alert("all characters");
4. Email format verification
---------------- -----------------------
//Function name: chkemail
//Function introduction: Check whether it is an Email Address
// Parameter description: String to be checked
//Return value: 0: Not 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. Number format verification
---------------------------------------
//Function name: fucCheckNUM
//Function introduction: Check whether it is a number
//Parameter description: The number to be checked
//Return value: 1 means it is a number, 0 means it is not a number
function fucCheckNUM(NUM)
{
var i,j,strTemp;
strTemp="0123456789";
if ( NUM.length== 0)
return 0
for (i=0;i{
j=strTemp.indexOf(NUM.charAt(i));
if (j==-1)
{
//Indicates that there are characters that are not Number
return 0;
}
}
//The description is number
return 1;
}
6. Phone number format verification
----- ----------------------------------
//Function name: fucCheckTEL
//Function introduction : Check whether it is a phone number
//Parameter description: The string to be checked
//Return value: 1 is legal, 0 is illegal
function fucCheckTEL(TEL)
{
var i,j,strTemp;
strTemp="0123456789-()# ";
for (i=0;i{
j=strTemp.indexOf (TEL.charAt(i));
if (j==-1)
{
//Indicates that some characters are illegal
return 0;
}
}
//Explanation is legal
return 1;
}
7. Function to determine whether the input is Chinese
-------------------------- ------------------
function ischinese(s){
var ret=true;
for(var i=0;iret=ret && (s.charCodeAt(i)>=10000);
return ret;
}
8. Comprehensive function to judge the legality of user input
---------------------------------------

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
JavaScript and the Web: Core Functionality and Use CasesJavaScript and the Web: Core Functionality and Use CasesApr 18, 2025 am 12:19 AM

The main uses of JavaScript in web development include client interaction, form verification and asynchronous communication. 1) Dynamic content update and user interaction through DOM operations; 2) Client verification is carried out before the user submits data to improve the user experience; 3) Refreshless communication with the server is achieved through AJAX technology.

Understanding the JavaScript Engine: Implementation DetailsUnderstanding the JavaScript Engine: Implementation DetailsApr 17, 2025 am 12:05 AM

Understanding how JavaScript engine works internally is important to developers because it helps write more efficient code and understand performance bottlenecks and optimization strategies. 1) The engine's workflow includes three stages: parsing, compiling and execution; 2) During the execution process, the engine will perform dynamic optimization, such as inline cache and hidden classes; 3) Best practices include avoiding global variables, optimizing loops, using const and lets, and avoiding excessive use of closures.

Python vs. JavaScript: The Learning Curve and Ease of UsePython vs. JavaScript: The Learning Curve and Ease of UseApr 16, 2025 am 12:12 AM

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

Python vs. JavaScript: Community, Libraries, and ResourcesPython vs. JavaScript: Community, Libraries, and ResourcesApr 15, 2025 am 12:16 AM

Python and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.

From C/C   to JavaScript: How It All WorksFrom C/C to JavaScript: How It All WorksApr 14, 2025 am 12:05 AM

The shift from C/C to JavaScript requires adapting to dynamic typing, garbage collection and asynchronous programming. 1) C/C is a statically typed language that requires manual memory management, while JavaScript is dynamically typed and garbage collection is automatically processed. 2) C/C needs to be compiled into machine code, while JavaScript is an interpreted language. 3) JavaScript introduces concepts such as closures, prototype chains and Promise, which enhances flexibility and asynchronous programming capabilities.

JavaScript Engines: Comparing ImplementationsJavaScript Engines: Comparing ImplementationsApr 13, 2025 am 12:05 AM

Different JavaScript engines have different effects when parsing and executing JavaScript code, because the implementation principles and optimization strategies of each engine differ. 1. Lexical analysis: convert source code into lexical unit. 2. Grammar analysis: Generate an abstract syntax tree. 3. Optimization and compilation: Generate machine code through the JIT compiler. 4. Execute: Run the machine code. V8 engine optimizes through instant compilation and hidden class, SpiderMonkey uses a type inference system, resulting in different performance performance on the same code.

Beyond the Browser: JavaScript in the Real WorldBeyond the Browser: JavaScript in the Real WorldApr 12, 2025 am 12:06 AM

JavaScript's applications in the real world include server-side programming, mobile application development and Internet of Things control: 1. Server-side programming is realized through Node.js, suitable for high concurrent request processing. 2. Mobile application development is carried out through ReactNative and supports cross-platform deployment. 3. Used for IoT device control through Johnny-Five library, suitable for hardware interaction.

Building a Multi-Tenant SaaS Application with Next.js (Backend Integration)Building a Multi-Tenant SaaS Application with Next.js (Backend Integration)Apr 11, 2025 am 08:23 AM

I built a functional multi-tenant SaaS application (an EdTech app) with your everyday tech tool and you can do the same. First, what’s a multi-tenant SaaS application? Multi-tenant SaaS applications let you serve multiple customers from a sing

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools