ipvalidator

IP Syntax Validation (ipv4/ipv6)
3 followers

IPValidator checks if an IP address is technically correct.

Documentation

Requirements

  • Yii 1.0 or above

Installation

  • Extract the release file under protected/extensions

Usage

The following model code validates against the ipv4 regex:

public function rules()
{
   return array(
      array('ipAddr', 'application.extensions.ipvalidator.IPValidator', 'version' => 'v4')
           );
}

While the following validates against the ipv6 regex: [php] public function rules() { return array( array('ipAddr', 'application.extensions.ipvalidator.IPValidator', 'version' => 'v4') ); }

Change Log

1.1 - ipv4 bug fixed (Thanks to beesnept) - ipv6 support added (Thanks to Rich Brown for his regex) 1.0 - initial version

Total 2 comments

#1201 report it
beesnept at 2009/10/29 04:52am
Regexp error

I'm sorry I mispelled the syntax, the correct regexp is:

/^(([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/
#1202 report it
beesnept at 2009/10/29 04:42am
Regexp error

The regular expression is not correct, as it considers IP addresses like 10a0a0a1 as valid. We need to use . instead of . to match for the dot character so we have to change the regular expression to

/^(([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]).){3}([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/

Leave a comment

Please to leave your comment.

Create extension
  • License: Other Open Source License
  • Developed by: eval
  • Category: Validation
  • Votes: +3
  • Downloaded: 755 times
  • Created on: Nov 26, 2008
  • Last updated: Jun 11, 2010