
For the admin there was a task - to make it convenient to enter ip-addresses.
The existing plugins did not suit the fact that they either did not accurately check the format and allowed to enter ip type 264.734.443.332, or did not know how to set separators themselves, or when entering an octet larger than 255 reduced to the smallest, i.e. when you enter 665 instead of putting a separator after the 66, i.e. make 66.5 reduced to 255, i.e. no convenience.
As a result, there was a desire to make a plug-in that would allow only numbers to be entered, and the point separators would be set in the right places themselves, whenever possible.
')
This is my first plugin, there was no creation experience, I decided to redo the existing similar plugin.
In order not to fence a bunch of conditions of conditions and exceptions to check the input of characters, it was decided to check the entered string by a regular expression. If every character entered matches, great. If not, try this symbol with a separator.
One regular expression checks the full string of the ip-address, the other checks whether the string can be part of the ip-address.
As a result, the code turned out to be small and the plugin performs the main function.
If someone needs
plugin operation example (updated 03/07/2014)
githubFrom what could be done:
Of course, it would be a plus to enter ip.v6, and with the support of the abbreviated form, I think to do it as soon as it is needed in our admin panel.
upt (03/07/2014):- Fixed bugs
- Added placeholder
- Added ability to edit individual octets.