Skip to content

Instantly share code, notes, and snippets.

@yannisxu
Created December 4, 2012 09:22
Show Gist options
  • Save yannisxu/4202129 to your computer and use it in GitHub Desktop.
Save yannisxu/4202129 to your computer and use it in GitHub Desktop.
Javascript:IPRegular
obj="1.1.1.1"
//ip地址
var exp=/^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/;
var reg = obj.match(exp);
if(reg==null)
{
alert("IP地址不合法!");
}
else
{
alert("IP地址合法!");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment