filter with pattern range of ports

2

I would like to know how you can filter with pattern a range of ports such that only accept or numbers or numbers with two points in between and as long as it does not exceed 65535.

Example: 20 or 20:25

The only thing that has occurred to me has been this filter pattern="[0-9] {1,5}" The only thing it does is to limit numbers of no more than five figures

    
asked by Takyo 13.06.2016 в 09:50
source

1 answer

4

To allow you to enter a number or two numbers separated by : , just complete your pattern <puerto> to be <puerto>(:<puerto>)? : ():

pattern="[0-9]{1,5}(:[0-9]{1,5})?"

So that it does not allow entering numbers greater than 65535, it is more complicated, but not impossible with a little ingenuity:

pattern="([1-9][0-9]{0,3})|([1-5][0-9]{4})|(6[0-4][0-9]{3})|(65[0-4][0-9]{2})|(655[0-2][0-9])|(6553[0-5])">

Now it only remains to combine both in (<puerto>)(:(<puerto>))? :

pattern="(([1-9][0-9]{0,3})|([1-5][0-9]{4})|(6[0-4][0-9]{3})|(65[0-4][0-9]{2})|(655[0-2][0-9])|(6553[0-5]))(:(([1-9][0-9]{0,3})|([1-5][0-9]{4})|(6[0-4][0-9]{3})|(65[0-4][0-9]{2})|(655[0-2][0-9])|(6553[0-5])))?">
    
answered by 13.06.2016 / 11:22
source