serverside url validation

serverside url validation

rostrost Posts: 26Questions: 9Answers: 1

Description of problem:
I want to validate urls serversideusing code like this:

            Field::inst( 'NameOfField' )
                    ->validator( Validate::url( 
                                                  ValidateOptions::inst()
                                  ->message( 'ErrorMessage' )
                ) )

With this I encounter several oddities: in my tests

What do I do wrong?

Or is this behaviour intentional? I read you are using a library (https://www.npmjs.com/package/valid-url/v/1.0.3), and they say it validates "relatively 'real-world' " ...

As a workaround I did some experiments with 'pinging' the adresses, which works, but not solid rock - so it would be very nice if someone could help me out.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin
    Answer ✓

    Our PHP libraries use the built in validate filters in PHP (note your link is to a NodeJS package which our PHP libraries do not use).

    What you have above are technically valid URLs which is why they are passing (see this SO thread).

    If you want to be a bit more strict, you might need to use a custom validator with a function similar to one of the answers further down in that thread - there is a is_url function which looks like it will do what you are looking for.

    Allan

  • rostrost Posts: 26Questions: 9Answers: 1

    Thanks a lot, I will check this :-)

This discussion has been closed.