JavaScript several commonly used form input judgments

Source: Internet
Author: User
Tags date format contains return
JavaScript//Function name: Chksafe
Function Description: Check whether contains "'", ' \ \ ', '/'
Parameter description: The string to check
Return value: 0: is 1: not

function Chksafe (a)
{
return 1;
/* Fibdn = new Array ("'", "\ \", ",", ",", ";", "/");
I=fibdn.length;
J=a.length;
for (ii=0;ii<i;ii++)
{for (jj=0;jj<j;jj++)
{Temp1=a.charat (JJ);
TEMP2=FIBDN[II];
if (TEM ';p 1==temp2)
{return 0;}
}
}
return 1;
*/
}

Function Name: CHKSPC
Feature Description: Check to see if any spaces are included
Parameter description: The string to check
Return value: 0: is 1: not

function CHKSPC (a)
{
var i=a.length;
var j = 0;
var k = 0;
while (K<i)
{
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 Introduction: Check whether for email address
Parameter description: The string to check
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;
}//OPT1 Decimal Opt2 Negative number
Check if NUM is negative when OPT2 is 1 o'clock
Check to see if NUM is a decimal when OPT1 is 1 o'clock
Return 1 is correct, 0 is wrong
function Chknbr (NUM,OPT1,OPT2)
{
var i=num.length;
var Staus;
The number of staus used for recording.
status=0;
if ((opt2!=1) && (num.charat (0) = = '-")
{
Alert ("You have enter a invalid number.");
return 0;

}
An error occurred when the last one was.
if (Num.charat (i-1) = = '. ')
{
Alert ("You have enter a invalid number.");
return 0;
}

for (j=0;j<i;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
Parameter description: The string to check
Return value: 0: Not date 1: is the 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<lthdatestr;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&GT;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 isn't 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 Introduction: Check whether contains not the numeral or the letter
Parameter description: The string to check
Return value: 0: Contains 1: all digits or letters


function Fucpwdchk (str)
{
var strsource = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
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
Feature Description: Check for numbers
Parameter description: The number to check
Return value: 1 is a number, 0 is not a number

function Fucchecknum (NUM)
{
var i,j,strtemp;
strtemp= "0123456789";
if (num.length== 0)
return 0
for (i=0;i<num.length;i++)
{
J=strtemp.indexof (Num.charat (i));
if (j==-1)
{
Indicates that a character is not a number
return 0;
}
}
Description is a number
return 1;
}
Function Name: Fucchecktel
Function Description: Check whether the phone number
Parameter description: The string to check
Return value: 1 is legal, 0 is illegal

function Fucchecktel (TEL)
{
var i,j,strtemp;
Strtemp= "0123456789-() #";
for (i=0;i<tel.length;i++)
{
J=strtemp.indexof (Tel.charat (i));
if (j==-1)
{
Indicates that there are characters that are not legal
return 0;
}
}
Description Legal
return 1;
}

Function Name: fucchecklength
Feature Description: Check the length of the string
Parameter description: The string to check
Return value: Length value

function Fucchecklength (strtemp)
{
var i,sum;
sum=0;
for (i=0;i<strtemp.length;i++)
{
if ((Strtemp.charcodeat (i) >=0) && (Strtemp.charcodeat (i) <=255))
sum=sum+1;
Else
sum=sum+2;
}
return sum;
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.