}
Return true;
}
// Verify the negative value
Function checknegative (Val, Min, Max, mode ){
If (mode = 0) & (Val. value = "")){
Return true;
}
If (! Checknumber (Val, Min, Max, mode )){
Val. Focus ();
Val. Select ();
Return false;
}
If (parseint (Val. Value)> = 0 ){
Alert ("data must be a valid negative integer. ");
Val. Focus ();
Val. Select ();
Return false;
}
Return true;
}
// Verify the floating point value
Function checkfloat (Val, Min, Max, mode ){
If (mode = 0) & (Val. value = "")){
Return true;
}
VaR Len = Val. value. length;
If (LEN <min | Len> MAX ){
Alert ("enter the correct floating point value. ");
Val. Focus ();
Val. Select ();
Return false;
}
VaR val2 = Val. value;
For (I = 1; I <val2.length; I ++ ){
VaR CH = val2.charat (I );
If (CH <"0" | ch> "9 ")){
If (Ch! = "."){
Alert ("enter the correct floating point value. ");
Val. Focus ();
Val. Select ();
Return false;
}
}
}
If (isnan (val2 )){
Alert ("enter the correct floating point value. ");
Val. Focus ();
Val. Select ();
Return false;
}
Else if (val2.indexof ('0') = 0 & val2.indexof ('.')! = 1 ){
Alert ("enter the correct valid floating point value. ");
Val. Focus ();
Val. Select ();
Return false;
}
Else if (val2.indexof ('-') = 0 & val2.indexof ('0') = 1 & val2.indexof ('.')! = 2 ){
Alert ("enter the correct valid floating point value. ");
Val. Focus ();
Val. Select ();
Return false;
}
Else if (val2.indexof ('-') = 0 & val2.indexof ('.') = 1 ){
Alert ("enter the correct valid floating point value. ");
Val. Focus ();
Val. Select ();
Return false;
}
Else if (val2.indexof ('.') = 0 ){
Alert ("enter the correct valid floating point value. ");
Val. Focus ();
Val. Select ();
Return false;
}
Return true;
}
// Verify the file path
Function checkpath (Val, mode ){
If (mode = 0) & (Val. value = "")){
Return true;
}
VaR val2 = Val. value;
If (val2.indexof (': \')> 0 ){
VaR isnot = "! @ # $ ^ *()''~ |]} [{;.>, <? % & + = ";
If (val2.indexof ('\ "')> 0 ){
Alert ("enter the correct file path. ");
Val. Focus ();
Val. Select ();
Return false;
}
Else {
For (VAR I = 0; I <val2.length; I ++ ){
For (VAR x = 1; x <isnot. length; X ++ ){
If (val2.charat (I) = isnot. charat (x )){
Alert ("enter the correct file path. ");
Val. Focus ();
Val. Select ();
Return false;
}
}
}
}
}
Else {
Alert ("enter the correct file path. ");
Val. Focus ();
Val. Select ();
Return false;
}
Return true;
}
// Verify the URL
Function checkurl (Val, mode ){
If (mode = 0) & (Val. value = "")){
Return true;
}
VaR val2 = Val. value;
If (val2.indexof (': //')> 0 ){
VaR isnot = "! @ $ ^ *()''~ |]} [{;. >,< ";
If (val2.indexof ('\ "')> 0 ){
Alert ("enter the correct URL. ");
Val. Focus ();
Val. Select ();
Return false;
}
Else {
For (VAR I = 0; I <val2.length; I ++ ){
For (VAR x = 1; x <isnot. length; X ++ ){
If (val2.charat (I) = isnot. charat (x )){
Alert ("enter the correct URL. ");
Val. Focus ();
Val. Select ();
Return false;
}
}
}
}
}
Else {
Alert ("enter the correct URL. ");
Val. Focus ();
Val. Select ();
Return false;
}
Return true;
}
// Verify the ID card
Function checkchinaidcard_j (Val, mode ){
If (mode = 0) & (Val. value = "")){
Return true;
}
Sno = Val. value. tostring ()
If (! Isinteger (SNO )){
Alert ("enter the correct ID card. ");
Val. Focus ();
Val. Select ();
Return false
}
Switch (Sno. Length ){
Case 15: If (isvaliddate (Sno. substr (6, 2), Sno. substr (8, 2), Sno. substr (10, 2 ))){
Return true
}
Case 17: If (isvaliddate (Sno. substr (6, 4), Sno. substr (10, 2), Sno. substr (12, 2 ))){
Return true
}
}
Alert ("enter the correct ID card. ");
Val. Focus ();
Val. Select ();
Return false
}
Function isinteger (snum ){
VaR num
Num = new Regexp ('[^ 0-9 _]', '')
If (isnan (snum )){
Return false
}
Else {
If (snum. Search (Num)> = 0 ){
Return false
}
Else {
Return true
}
}
}
// Verify the zip code
Function checkzip (Val, slen, mode ){
If (mode = 0) & (Val. value = "")){
Return true;
}
If (Val. value. length! = Slen ){
Alert ('Enter the correct zip code !! ');
Val. Focus ();
Val. Select ();
Return false
}
VaR r1
R1 = new Regexp ('[^ 0-9]', '');
If (Val. value. Search (R1)> = 0 ){
Alert ('Enter the correct zip code !! ');
Val. Focus ();
Val. Select ();
Return false
}
Else
Return true;
}
Phone number verification
Requirements:
(1) Telephone Numbers consist of numbers, "(", ")", and "-"
(2) 3 to 8 phone numbers
(3) If the telephone number contains a district code, the district code is three or four digits.
(4) area codes are separated by "(", ")" or "-" and other sections.
(5) the mobile phone number is 11 or 12 digits. If the mobile phone number is 12 digits, the first digit is 0.
(6) The first and second digits of 11 mobile phone numbers are "13"
(7) The second and third digits of the 12-digit mobile phone numbers are "13"
Based on these rules, you can use the following regular expressions:
(^ [0-9] {3, 4} \-[0-9] {3, 8} $) | (^ [0-9] {3, 8} $) | (^ \ ([0-9] {3, 4} \) [0-9] {3, 8} $) | (^ 0 {0, 1} 13 [0-9] {9} $)
<Script language = "JavaScript">
Function phonecheck (s ){
VaR STR = s;
VaR Reg =/(^ [0-9] {3, 4} \-[0-9] {3, 8} $) | (^ [0-9] {3, 8} $) | (^ \ ([0-9] {3, 4} \) [0-9] {3, 8} $) | (^ 0 {0, 1} 13 [0-9] {9} $ )/
Alert (Reg. Test (STR ));
}
</SCRIPT>
<Input type = text name = "iPhone">
<Input type = button onclick = "phonecheck (document. All. iPhone. Value)" value = "check">
// Function name: chksafe
// Function Description: Check whether "'",' \ ', "/" is contained "'",'\\',"/"
// Parameter description: the string to be checked
// Return value: 0: Yes 1: No
Function chksafe ()
{
Return 1;
/* Maid = new array ("'","\\",",",",",";","/");
I = maid. length;
J = A. length;
For (II = 0; II {for (JJ = 0; JJ {temp1 = A. charat (jj );
Temp2 = maid [II];
If (temp1 = temp2)
{Return 0 ;}
}
}
Return 1;
*/
}
// Function name: chkspc
// Function Description: Check whether space exists.
// Parameter description: the string to be checked
// Return value: 0: Yes 1: No
Function chkspc ()
{
VaR I = A. length;
VaR J = 0;
VaR K = 0;
While (K {
If (A. charat (k )! = "")
J = J + 1;
K = k + 1;
}
If (j = 0)
{
Return 0;
}
If (I! = J)
{Return 2 ;}
Else
{
Return 1;
}
}
// Function name: chkemail
// Function Description: Check whether the email address is used
// Parameter description: the string to be checked
// Return value: 0: Not 1: Yes
Function chkemail ()
{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;
} // Opt1 decimal opt2 negative
// When opt2 is 1, check if num is negative.
// When opt1 is 1, check whether num is a decimal number.
// 1 is returned and 0 is incorrect.
Function chknbr (Num, opt1, opt2)
{
VaR I = num. length;
VaR staus;
// The number of staus records.
Status = 0;
If (opt2! = 1) & (Num. charat (0) = '-'))
{
// Alert ("You have enter a invalid number .");
Return 0;
}
// An error occurs when the last digit is.
If (Num. charat (I-1) = '.')
{
// Alert ("You have enter a invalid number .");
Return 0;
}
For (j = 0; J {
If (Num. charat (j) = '.')
{
Status ++;
}
If (status> 1)
{
// Alert ("You have enter a invalid number .");
Return 0;
}
If (Num. charat (j) <'0' | num. charat (j)> '9 ')
{
If (opt1 = 0) | (Num. charat (j )! = '.') & (J! = 0 ))
{
// Alert ("You have enter a invalid number .");
Return 0;
}
}
}
Return 1;
}
// Function name: chkdate
// Function Description: Check whether the date is used
// Parameter description: the string to be checked
// Return value: 0: Not date 1: Date
Function chkdate (datestr)
{
VaR lthdatestr
If (datestr! = "")
Lthdatestr = datestr. length;
Else
Lthdatestr = 0;
VaR tmpy = "";
VaR tmpm = "";
VaR tmpd = "";
// Var datestr;
VaR status;
Status = 0;
If (lthdatestr = 0)
Return 0
For (I = 0; I {If (datestr. charat (I) = '-')
{
Status ++;
}
If (status> 2)
{
// Alert ("invalid format of date! ");
Return 0;
}
If (status = 0) & (datestr. charat (I )! = '-'))
{
Tmpy = tmpy + datestr. charat (I)
}
If (status = 1) & (datestr. charat (I )! = '-'))
{
Tmpm = tmpm + datestr. charat (I)
}
If (status = 2) & (datestr. charat (I )! = '-'))
{
Tmpd = tmpd + datestr. charat (I)
}
}
Year = new string (tmpy );
Month = new string (tmpm );
Day = new string (tmpd)
// Tempdate = new string (Year + month + Day );
// Alert (tempdate );
If (tmpy. length! = 4) | (tmpm. length> 2) | (tmpd. length> 2 ))
{
// Alert ("invalid format of date! ");
Return 0;
}
If (! (1 <= month) & (12> = month) & (31> = day) & (1 <= day )))
{
// Alert ("invalid month or day! ");
Return 0;
}
If (! (Year % 4) = 0) & (month = 2) & (Day = 29 ))
{
// Alert ("This is not a leap year! ");
Return 0;
}
If (month <= 7) & (month % 2) = 0) & (day> = 31 ))
{
// Alert ("this month is a small month! ");
Return 0;
}
If (month> = 8) & (month % 2) = 1) & (day> = 31 ))
{
// Alert ("this month is a small month! ");
Return 0;
}
If (month = 2) & (Day = 30 ))
{
// Alert ("The febryary never has this day! ");
Return 0;
}
Return 1;
}
// Function name: fucpwdchk
// Function Description: Check whether there are non-numbers or letters
// Parameter description: the string to be checked
// Return value: 0: containing 1: All numbers or letters
Function fucpwdchk (STR)
{
VaR strsource = "0123456789 abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz ";
VaR ch;
VaR I;
VaR temp;
For (I = 0; I <= (Str. Length-1); I ++)
{
Ch = Str. charat (I );
Temp = strsource. indexof (CH );
If (temp =-1)
{
Return 0;
}
}
If (strsource. indexof (CH) =-1)
{
Return 0;
}
Else
{
Return 1;
}
}
Function jtrim (STR)
{While (Str. charat (0) = "")
{STR = Str. substr (1 );}
While (Str. charat (Str. Length-1) = "")
{STR = Str. substr (0, str. Length-1 );}
Return (STR );
}
// Function name: fucchecknum
// Function Description: Check whether it is a number
// Parameter description: number to be checked
// Return value: 1 is a number, and 0 is not a number
Function fucchecknum (Num)
{
VaR I, j, strtemp;
Strtemp = "0123456789 ";
Http://www.feel123.cn/jscs/index.html reference