• 1058 views
  • 0 comments
  • loading...

Special type validator

IS_IPV4 validator checks if a field's value is an IP version 4 address in decimal form. Can be set to force addresses from a certain range.
(IPv4 regex taken from ref.[regexlib])

All three example values are equal, since addresses are converted to integers for inclusion check with following function:

number = 16777216 * IP[0] + 65536 * IP[1] + 256 * IP[2] + IP[3]





# Check for valid IPv4 address:

requires = IS_IPV4()

#Check for valid private network IPv4 address:
requires = IS_IPV4(minip='192.168.0.1', maxip='192.168.255.255')

Attributes / Arguments

Lowest allowed address; accepts: str, e.g., 192.168.0.1; iterable of numbers, e.g., [192, 168, 0, 1]; int, e.g., 3232235521

requires = IS_IPV4(minip='192.168.0.1')

Highest allowed address; accepts: str, e.g., 192.168.0.1; iterable of numbers, e.g., [192, 168, 0, 1]; int, e.g., 3232235521

requires = IS_IPV4(maxip='192.168.255.255')


loading...

Sources / Reference

" Web2py Book"


Comments

loading...

Powered by
Web2py

Hosted on
www.pythonanywhere.com
(affiliated link)