Common email address IP address English user name validation function

Source: Internet
Author: User

Common email address IP address English user name validation function

*/
function to check e-mail address like string
function Isemail (s)
{
There must is >= 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 is at least one character after the.
if ((i >= slength-1) | | (S.charat (i)!= ".")) return false;
else return true;
}

Verify that the IP address is used primarily with regular ([0-9]{1,3}) [.] {1,} ([0-9]{1,3}) [.] {1,} ([0-9]{1,3}) [.] {1,} ([0-9]{1,3}) to deal with, because IP is 1.1.1.1 this rule oh, so we just have to conform to the rules on the line. function to check IP addresses 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;
}

User name as long as we first define a abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789-._@ and then traverse the judgment if it does not exist it is not legal.
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);
 }

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.