jeudi 22 mai 2014

c# - création d'une zone de texte conforme pour IPv4 et IPv6 - Stack Overflow


As regex could be not the optimal solution for validating the IP addresses, as my need would be to validate for both IPv4 and IPv6. Is there a solution that already addresses the support of input of IPv4 as well as IPv6.




The normal TextBox supports the input of both IPv4 addresses and IPv6 addresses as well as any other text. If you're looking for a control that accepts only IPv4 addresses and IPv6 addresses -- don't do this.


IP addresses (and in particular IPv6 addresses) are seldom entered from scratch. Most of the time they are copied from somewhere else and are not necessarily in the right format. If the address is not in the right format, the user often cannot change it in the place where it's copied from -- the user needs to be able to paste it into the TextBox and edit it there. This is not possible if the TextBox does not accept invalid input.


Solution: use a normal TextBox and validate the input when the user clicks the Submit/Next/OK button.




You need to have a look at the following two projects, you should find these extremely useful:


http://code.google.com/p/ipaddresscontrollib/


https://code.google.com/p/flexfieldcontrollib/



As regex could be not the optimal solution for validating the IP addresses, as my need would be to validate for both IPv4 and IPv6. Is there a solution that already addresses the support of input of IPv4 as well as IPv6.



The normal TextBox supports the input of both IPv4 addresses and IPv6 addresses as well as any other text. If you're looking for a control that accepts only IPv4 addresses and IPv6 addresses -- don't do this.


IP addresses (and in particular IPv6 addresses) are seldom entered from scratch. Most of the time they are copied from somewhere else and are not necessarily in the right format. If the address is not in the right format, the user often cannot change it in the place where it's copied from -- the user needs to be able to paste it into the TextBox and edit it there. This is not possible if the TextBox does not accept invalid input.


Solution: use a normal TextBox and validate the input when the user clicks the Submit/Next/OK button.



You need to have a look at the following two projects, you should find these extremely useful:


http://code.google.com/p/ipaddresscontrollib/


https://code.google.com/p/flexfieldcontrollib/


0 commentaires:

Enregistrer un commentaire