Forum Discussion

Eljay's avatar
Eljay
Icon for Cirrus rankCirrus
Jun 27, 2019

Using SCAN to validate an URI

I need to validate an URI. I'd like to use a policy but iRule works as well.

 

I need to check if an URI is between 2 and 8 characters long and that it contains only digits and upper or lower letters. The regex expression is something like this " ^[a-zA-Z0-9]{2,8} ", but how can I use scan to do the same thing.

 

If the validation fails then I want to reset the connection, if it is a valid URI then I want to send it to the pool.

 

How can I solve this problem?

 

Thanks in advance.

1 Reply

    1. URI always starts with / so your regex expression may not work.
    2. scan command is not the best solution to define length filtering

     

    You can use following code in you irule to check both length filtering and format:

     

    set uri [string range [HTTP::uri] 2 end]
    if {([set length [string length $uri]] == 8 || $length == 2 ) && [string is alnum $uri ]} {
      #actions if true
    } else {
      #actions if false
    }