JS Form Verification Daquan _ form special effects
Last Update:2017-05-11
Source: Internet
Author: User
Javascript form verification is complete. You can search for it if you need it. 1. Only numbers and English letters can be entered:
2. Only numbers can be entered:
3. Only the fullwidth fields can be entered:
4. Only Chinese characters can be entered:
--------------------------------------------------------------------------------
Verify invalid characters, SQL
Function vdf ()
{
Var I, j, name, value, message, length, type, a = vdf. arguments, cb_name;
For (I = 0; I <(a. length-2); I + = 3)
{
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 when it is null
Return false;
}
}
// ======================== Determine whether to select the drop-down box ============================ //
If (type = "r_sl ")
{
If (name. selected = false)
{
Alert (message + "! /N "); // The prompt when it is null
Return false;
}
}
// ========================== Cannot be empty //
If (type = "r ")
{
If (value = "") // determines whether it is null
{
Alert (message + "! /N "); // The prompt when it is null
Name. focus ();
Name. select ();
Return false;
}
}
// ======================== Cannot be empty, but do not get focus ============================ //
If (type = "o_r ")
{
If (value = "") // determines whether it is null
{
Alert (message + "! /N "); // The prompt when it is null
Return false;
}
}
// ======================== Only Chinese characters can be entered ============================== //
If (type = "r_china ")
{
If (value. search (/^ [/u4e00-/u9fa5] + $/) =-1)
{
Alert (message + "! /N "); // cannot be empty
Name. focus ();
Name. select ();
Return false;
}
}
// ======================== Cannot be blank, must be a number or character ============================== //
If (type = "r_num_char ")
{
If (value = "")
{
Alert (message + "! /N "); // The prompt when it is null
Name. focus ();
Name. select ();
Return false;
}
If (value. search (/^ [0-9a-zA-Z] + $/) =-1)
{
Alert (message + "! /N "); // The prompt when it is null
Name. focus ();
Name. select ();
Return false;
}
}
// ======================== Can be empty, not empty, enter a number ============================ //
If (type = "num ")
{
If (value. search (/^ [0-9] + $/) =-1 & value! = "")
{
Alert (message + "! /N "); // cannot be empty
Name. focus ();
Name. select ();
Return false;
}
}
// ======================== Cannot be blank, must be a number to determine ============================ //
If (type = "r_num ")
{
If (value = "")
{
Alert (message + "! /N ");
Name. focus ();
Name. select ();
Return false;
}
If (value. search (/^ [0-9] + $/) =-1)
{
Alert (message + "! /N "); // cannot be empty
Name. focus ();
Name. select ();
Return false;
}
}
// ========================== Numbers smaller than n must be entered//
If (type. indexOf ("r_num <")! =-1)
{
Length = type. substring (type. indexOf ('<') + 1), type. length); // obtain rn <后面的数
If (value = "") // prompt for empty
{
Alert (message + "! /N ");
Name. focus ();
Name. select ();
Return false;
}
If (value. search (/^ [0-9] + $/) =-1) // The prompt is not composed of numbers.
{
Alert (message + "! /N ");
Name. focus ();
Name. select ();
Return false;
}
If (value. length> length) // limits the number length.
{
Alert (message + "! /N ");
Name. focus ();
Name. select ();
Return false;
}
}
// ========================== Numbers greater than n must be input//
If (type. indexOf ("r_num> ")! =-1)
{
Length = type. substring (type. indexOf ('>') + 1), type. length); // obtain rn <后面的数
If (value = "") // prompt for empty
{
Alert (message + "! /N ");
Name. focus ();
Name. select ();
Return false;
}
If (value. search (/^ [0-9] + $/) =-1) // The prompt is not composed of numbers.
{
Alert (message + "! /N ");
Name. focus ();
Name. select ();
Return false;
}
If (value. length {
Alert (message + "! /N ");
Name. focus ();
Name. select ();
Return false;
}
}
// ========================== Numbers between a and B must be entered == //
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) // obtain rn <后面的数
If (value = "") // prompt for empty
{
Alert (message + "! /N ");
Name. focus ();
Name. select ();
Return false;
}
If (value. search (/^ [0-9] + $/) =-1) // The prompt is not composed of numbers.
{
Alert (message + "! /N ");
Name. focus ();
Name. select ();
Return false;
}
If (value. length Length1) // limits the number length.
{
Alert (message + "! /N ");
Name. focus ();
Name. select ();
Return false;
}
}
// ======================== Cannot be blank, it must be of the 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 "); // cannot be empty
Name. focus ();
Name. select ();
Return false;
}
}
// ====================== Determine email, not necessarily input ============================== //
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 the email, 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;
}
}
// ====================== Judge the date, for example, 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) // The input format is correct.
{
Flag = false;
}
Else
{
Var year = getdate. substr (0, getdate. indexOf ('-') // obtain the year
// The following operations 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 gets 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) // 4,6, the month date cannot exceed 30
{
Flag = false;
}
If (month = 2) // judge January
{
If (LeapYear (year ))
{
If (day> 29 | day <1) {flag = false ;}
}
Else
{
If (day> 28 | day <1) {flag = false ;}
}
}
Else
{
Flag = true;
}
}
If (flag = false)
{
Alert (message + "! /N "); // The prompt when it is null
Name. focus ();
Name. select ();
Return false;
}
}
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
2. Only Chinese characters are allowed
3. "English only