常用邮箱地址 ip地址 英文用户名验证函数
*/
// function to check e-mail address like string
function isemail (s)
{
// there must be >= 1 character before @, so we
// start looking at character position 1
// (i.e. second character)
var i = 1;
var slength = s.length;if ( slength <= 1 ) return false ;
// look for @
while ((i < slength) && (s.charat(i) != "@"))
{ i++
}if ((i >= slength) || (s.charat(i) != "@")) return false;
else i += 2;// look for .
while ((i < slength) && (s.charat(i) != "."))
{ i++
}// there must be at least one character after the .
if ((i >= slength - 1) || (s.charat(i) != ".")) return false;
else return true;
}// 验证ip地址主要用到正则([0-9]{1,3})[.]{1,}([0-9]{1,3})[.]{1,}([0-9]{1,3})[.]{1,}([0-9]{1,3})来处理了,因为ip是1.1.1.1这种规则哦,所以我们只要是符合规则就行了。function to check ip address like string
function isipaddress ( stripaddress )
{
regexp = new regexp ( "([0-9]{1,3})[.]{1,}([0-9]{1,3})[.]{1,}([0-9]{1,3})[.]{1,}([0-9]{1,3})" ) ;
aparts = regexp.exec ( stripaddress ) ;
if ( aparts == null )
{
return false ;
}if ( aparts.length != 5 )
{
return false ;
}for ( nloopcnt = 1 ; nloopcnt < 5 ; nloopcnt ++ )
{
if ( aparts [ nloopcnt ] < 0 || aparts [ nloopcnt ] > 255 )
{
return false ;
}
}return true ;
}//用户名只要是我们先定义一abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789-._@再遍历判断如果是不存在就不是合法的。
function fn_checkloginname ( strlogin )
{
strlogin = trimstring( strlogin ) ;var checkok = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789-._@";
var checkstr = strlogin ;
var allvalid = true;
for (i = 0; i < checkstr.length; i++)
{
ch = checkstr.charat(i);
for (j = 0; j < checkok.length; j++)
if (ch == checkok.charat(j))
break;
if (j == checkok.length)
{
allvalid = false;
break;
}
}
if ( ! allvalid )
{
return (false);
}if ( checkstr.charat(0) == '-' || checkstr.charat(0) == '.' || checkstr.charat(0) == '_' )
{
return (false);
}return (true);
}