JG+ 检查字符串
检查字符串,要求必须包含数字和字母
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
//-----------------------------------------------------------------------------------------------------
int AllNum(char *str)
{
int i,nLen;
nLen=strlen(str);
for (i=0;i<nLen;i++)
{
if (isalnum(str[i])==0)
return (0);
}
return (1);
}
//-----------------------------------------------------------------------------------------------------
int AllDigit(char *str)
{
int i,nLen;
nLen=strlen(str);
for (i=0;i<nLen;i++)
{
if (str[i]<'0' || str[i]>'9')
return (0);
}
return (1);
}
//-----------------------------------------------------------------------------------------------------
int AllPha(char *str)
{
int i,nLen;
nLen=strlen(str);
for (i=0;i<nLen;i++)
{
if (isalpha(str[i])==0)
return (0);
}
return (1);
}
//------int CheckBarcode(char *szBarcode)------------------------------------------------------------------------------
int CheckBarcode(char *szBarcode)
{
int nLen;
nLen=strlen(szBarcode);
if(nLen<2 || nLen> 13)
return 0;
if(AllNum(szBarcode))//只有数字或字母,没有其他符号
{
if(AllPha(szBarcode))//纯字母
return 0;
else if(AllDigit(szBarcode))//纯数字
return 0 ;
else
return 1;
}
else
{
return 0;
}
}