IPValidator checks if an IP address is technically correct.
protected/extensionsThe 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') ); }
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
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])$/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 login to leave your comment.