Regular Expression to match IP address + wildcard

后端 未结 5 903
旧时难觅i
旧时难觅i 2021-01-02 21:57

I\'m trying to use a RegularexpressionValidator to match an IP address (with possible wildcards) for an IP filtering system.

I\'m using the following Regex:

5条回答
  •  無奈伤痛
    2021-01-02 22:10

    This: \\.|\\*\\. looks like the dodgy bit. Do this instead:

    @"^(([0-9]{1,3}|\*)\.){3}([0-9]{1,3}|\*)$"
    

    And to only accept 0-255 (thanks, apoorv020):

    ^((([0-9]{1,2})|(1[0-9]{2,2})|(2[0-4][0-9])|(25[0-5])|\*)\.){3}(([0-9]{1,2})|(1[0-9]{2,2})|(2[0-4][0-9])|(25[0-5])|\*)$
    

提交回复
热议问题