Skip to content

Instantly share code, notes, and snippets.

@egulhan
Created August 1, 2013 08:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save egulhan/7f19a5b7367031472db5 to your computer and use it in GitHub Desktop.
Save egulhan/7f19a5b7367031472db5 to your computer and use it in GitHub Desktop.
Check a IP is valid or not.
var
ip=attr.val(),
ipPatt=/^([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])$/;
// If invalid ip
if(!ipPatt.test(ip))
alert('invalid ip');
else
alert('valid ip');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment