Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Dec 2006
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    validate a form field

    I have a form field that is for a url.

    I have the value of the field http:// so that the users can add in www.site.com

    How do I validate:

    1) there is a website entered
    2) that it begins with http:// (in case they tabbed and deleted this part and only have www.site.com or just site.com)

    Thanks in advance.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,731
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    if (/^http:\/\/www\./i.test(lstr.value)) {
    Alert ("OK");
    }

    Tests that the field (lstr) starts with http://www.

    Obviously you cannot check that the URL entered is a valid one.

    Please don't use the gruesome expression "Thanks in advance". It is rude, and suggests that you take other's help for granted.

  • #3
    Regular Coder
    Join Date
    Jan 2006
    Posts
    243
    Thanks
    14
    Thanked 2 Times in 2 Posts
    I was thinking about this lately as I'm working on validation stuff as well.

    I need it for a guestbook, I want to automatically make the users name a link to his/her site. It should however work with all manners I think users are likely to enter their website. These include (but are probably not limmited to ):

    example.com
    www.example.com
    http://www.example.com

    I think the solution above only detects the first option. I haven't really worked on it yet, so I don't have anything better, I'd just like to know if there are any known fool-proof methods already out there.

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,731
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    Anyone silly enough to enter his web URL into a guest book needs to see a doctor right away. There is enough spam about already.

  • #5
    Regular Coder
    Join Date
    Jan 2006
    Posts
    243
    Thanks
    14
    Thanked 2 Times in 2 Posts
    Hardly a helpfull reply but it is a good point, I didn't thought of it before.

    However, anywhere I list my own email on my site I use a very basic script to split it up and put it back together at the clients machine. Works well, I can...

    Hey wait a min... url and spam? Since when are spambots looking for urls, what use are those?


    Anyway, in the CG scene a guestbook is very common, I left many a message with no trouble at all. Regardless, people are free to choose not to leave their site.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •