Common JS judgment
About registration; judgment on registration information:
Form
<Form ID = "form" name = "form" method = "Post" Action = "" onsubmit = "Return Checkpost ();">
Introduction: <script language = "JavaScript" src = "Js. js">
</SCRIPT>
The following is a judgment on the length of the input value.
<Script language = "JavaScript">
Function Checkpost ()
{
If (document. Form. username. value = ""
| Document. Form. passwd. value = "")
{
Alert ("each item needs to be filled in! ");
Return false;
}
If (document. Form. username. value. length> 5 ){
Alert ("the User Name Length cannot exceed five characters ");
Return false;
}
}
</SCRIPT>
Page jump to new page
<SCRIPT> window. Location = "index. php"; </SCRIPT>;
Tip: Close the window. How can I return to the home page after a new page is opened?
<A href = "index. php" onclick = "javascript: window. Close ();" Title = "back"> back to home >></A>
/Determine control visibility
Function iscontrolvisible (handle ){
VaR retvalue = true;
While (handle. tagname. tolowercase ()! = 'Form' & handle. style. display. tolowercase ()! = 'None '){
Handle = handle. parentelement;
}
If (handle. style. Display = 'None') retvalue = false;
Return retvalue;
}
// ============================== The above is the system function area ====================== ======== //
// The following is an instant verification function for input content during the input process.
// The value must be a number.
Function inputnumber (handle, keycode ){
If (! (Keycode >=48 & keycode <= 57) | (keycode >=96 & keycode <= 105 ))){
Window. event. returnvalue = false;
Return/"a number is required! That is, the following characters:
1234567890 /";
} Else return true;
}
// A letter is required
Function inputletter (handle, keycode ){
If (! (Keycode> = 97 & keycode <= 122) | (keycode> = 65 & keycode <= 90 ))){
Window. event. returnvalue = false;
Return/"uppercase/lowercase letters are required! That is, the following characters:
Abcdefghijklmnopqrstuvwxyz
Abcdefghijklmnopqrstuvwxyz /";
} Else return true;
}
// All visible characters must be entered
Function inputvisible (handle, keycode ){
VaR pattern =/"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789. @> <,-[] {}? /+ = | //////'///":;~! # $ % ()'/";
VaR keyValue = string. fromcharcode (keycode );
If (keycode = 190) keyValue = /"./";
If (keycode = 189) keyValue = /"-/";
If (keycode = 188) keyValue =/"</";
If (keycode = 219) keyValue = /"/";
If (keycode = 191) keyValue = /"? /";
If (keycode = 187) keyValue =/"+ /";
If (keycode = 220) keyValue =/"| /";
If (keycode = 222) keyValue = /"'/";
If (keycode = 186) keyValue = /";/";
If (keycode = 192) keyValue = /"~ /";
If (pattern. indexof (keyValue )! =-1 ){
Window. event. returnvalue = true;
Return true;
} Else {
Window. event. returnvalue = false;
Return/"visible characters must be entered! That is, the following characters:
Abcdefghijklmnopqrstuvwxyz
Abcdefghijklmnopqrstuvwxyz
0123456789. @> <,-[] {}? /+ = | //////'///":
;~! # $ % ()'/";
}
}
// You must enter letters and numbers.
Function inputnormal (handle, keycode ){
VaR pattern =/"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789 /";
VaR keyValue = string. fromcharcode (keycode );
If (pattern. indexof (keyValue )! =-1 ){
Window. event. returnvalue = true;
Return true;
} Else {
Window. event. returnvalue = false;
Return/"visible characters must be entered! That is, the following characters:
Abcdefghijklmnopqrstuvwxyz
Abcdefghijklmnopqrstuvwxyz
0123456789 /";
}
}
// ========================== The following is the verification function area ====================== ======== //
// Function Name Description: Is + typename. The first letter of typename is capitalized.
// The handle parameter is the current control handle.
// The keycode parameter is the value of the current button.
// Return Description: the reason for failing to return /"/"
/* Format supports example tables
Format description
Number Type
Userid
Username
Enterprisename Enterprise Name
Loginname
CardNumber ID number
Address
Phone number
Mobile phone number
Postcode zip code
Email
Name simplicity
Password
Namestr name string
Descstr description string
Pageurl page url
Dirctory disk path
*/
// Determine whether the unit ID is correct
Function isorganizationid (handle ){
VaR pattern =/^ (// d) {16, 16} $ /;
If (! Pattern.exe C (handle. Value )){
Handle. value =''
Return/"a 16-digit number is required! /";}
Return true;
}
// Determine whether it is a number
Function isnumber (handle ){
VaR pattern =/^ (// d) {1, 16} $ /;
If (! Pattern.exe C (handle. Value )){
Handle. value =''
Return/"a number is required! /";}
Return true;
}
// Determine whether the account is a user account
Function isuserid (handle ){
VaR pattern =/^ (// d | // W) {3, 14} $ /;
If (! Pattern.exe C (handle. Value) return/"a number is required.
And the length must be greater than or equal to 3 and less than or equal to 14! /";
Return true;
}
// Determine whether the user name can be a letter or a Chinese character
Function isusername (handle ){
VaR pattern =/^ {2, 50} $ /;
If (! Pattern.exe C (handle. Value) return/"must be a Chinese letter or number
The length must be greater than or equal to 2 and less than or equal to 50! /"
Return true;
}
// Determine whether it is a name: It can be letters, numbers, Chinese characters -_
Function isname (handle ){
VaR pattern =/^ {1, 30} $ /;
If (! Pattern.exe C (handle. Value) return/"must be a Chinese letter or number! /";
Return true;
}
// Determine whether the menu name is used: it can be a letter, digit, Chinese character -_
Function ismenuname (handle ){
VaR pattern =/^ {2,200} $ /;
If (! Pattern.exe C (handle. Value) {return/"must be a Chinese letter or number
The length must be greater than or equal to 2 and less than or equal to 40! /";
Handle. value =''
} Return true;
}
// Determine whether the logon name is used
Function isloginname (handle ){
VaR pattern =/^ (|) {2, 25} $ /;
If (! Pattern.exe C (handle. Value) return/"must be a letter or number
And the length must be greater than or equal to 2 and less than or equal to 25! /";
Return true;
}
// Determine whether the ID card number is used
Function iscardnumber (handle ){
VaR pattern;
Pattern =/^ (// d) {5, 18} $ /;
If (! Pattern.exe C (handle. Value) return/"must be a number
The length must be greater than or equal to 5 Characters and less than or equal to 16 characters! /";
Return true;
}
// Address
Function isaddress (handle ){
VaR pattern =/^ {2,200} $ /;
If (! Pattern.exe C (handle. Value) return/"must be a Chinese letter or number
The length must be greater than or equal to 2 and less than or equal to 200 characters! /";
Return true;
}
// Determine whether the phone number is correct
Function isphone (handle ){
VaR pattern =/^ (// d) {6, 30} $ /;
If (! Pattern.exe C (handle. Value) return/"must be a number
The length must be greater than or equal to 6 Characters and less than or equal to 30 characters! /";
Return true;
}
// Determine whether the zip code meets the requirements
Function ispostcode (handle ){
VaR pattern =/^ (// d) {6} $ /;
If (! Pattern.exe C (handle. Value) return/"must be a number
The length must be 6 characters! /";
Return true;
}
// Determine whether the email format is correct
Function isemail (handle ){
VaR pattern =/^ () + @ () + (//.) + /;
If (! Pattern.exe C (handle. Value) return/"must comply with the email address format /";
Return true;
}
// Simple search
Function isnamesimplicity (handle ){
VaR pattern =/^ () {2, 25} $ /;
If (! Pattern.exe C (handle. Value) return/"must be a letter
And the length must be greater than or equal to 2 and less than or equal to 25! /";
Return true;
}
// Determine whether the entered password is correct
Function ispassword (handle ){
VaR pattern =/^ (|) {2, 25} $ /;
If (! Pattern.exe C (handle. Value) return/"must be a letter or number
And the length must be greater than or equal to 2 and less than or equal to 25! /";
Return true;
}
// Determine whether it is a description: it can be a letter, number, Chinese character -_,.
Function isdescstr (handle ){
VaR pattern =/^ {1, 50} $ /;
If (! Pattern.exe C (handle. Value) return/"must be a Chinese letter or number
And the length must be greater than or equal to 1 and less than or equal to 50! /";
Return true;
}
// Determine whether the page url is correct
Function ispageurl (handle ){
VaR pattern =/^ +/. + [// = //? % //-&_~ '@/': +!] * () * $ /;
If (! Pattern.exe C (handle. Value )){
Return/"enter the correct URL format, such as A. do? B = 1 & C = 2 /";
Handle. value =''
}
Return true;
}
// Determine whether the version number is correct (the first is a number followed by A. Or number)
Function isversion (handle ){
VaR pattern =/^ // d {1} + * $ /;
If (! Pattern.exe C (handle. Value )){
Return/"enter the correct version format, such as 1.234 /";
Handle. value =''
}
Return true;
}
// Determine whether the system ID is correct (the System ID can only be a combination of numbers and letters)
Function issysid (handle ){
VaR pattern =/^ // W {1, 10} $ /;
If (! Pattern.exe C (handle. Value )){
Return/"must be a letter or number
And the length must be greater than or equal to 1 and less than or equal to 10! /";
Handle. value =''
}
Return true;
}
// Determine whether the directory path is correct
Function isdirctoryurl (handle ){
VaR pattern =/^ {1,300} $ /;
If (! Pattern.exe C (handle. Value) return/"must be a Chinese letter or number
The length must be greater than or equal to 1 and less than or equal to 300 characters! /";
Return true;
}