SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast appy's Avatar
    Join Date
    Feb 2002
    0 Post(s)
    0 Thread(s)

    Validating a suggested web link in a form

    Hi All,

    I am working on a form for a client which allows people to suggest a web page by inputting a link in a form field. I want to use Javascript to validate that the link is valid when the user submits the form but I'm no JS coder (just about getting to grasps with PHP!). I have searched round the usual sites (in the Javascript Resource Websites thread) and I cannot find any snippets to validate web links. Hundreds for validating email addresses but none for links. Could anyone suggest a quick bit of Javascript? Or any advice for me whilst I blunder my way through some JS pattern matching tutorials?

    I could do it through PHP but I would prefer this time to check when the user tries to submit the form and an alert to appear when the link is invalid.



  2. #2
    ♪♪ ♪ ♪ ♪ ♪♪ ♪ ♪♪ Markdidj's Avatar
    Join Date
    Sep 2002
    Bournemouth, South UK
    1 Post(s)
    0 Thread(s)

    this is where I'm at...reg exp

    Regular Expressions.


    looks weird eh?

    /^(file|http) checks if the first words are 'file' or 'http'

    then a ':' is required.

    the \/\/ escapes '//'s which are in the URL. \S+ is any number of any non-white space characters. Then another single \/ (checks for '/' in url) and another \S+ then a '.' then check for gif OR jpg all reg exp ends in $/ and the i allows for lower or uppercase letters.

    I'm finaly get my head round it!!!

    good luck
    LiveScript: Putting the "Live" Back into JavaScript
    if live output_as_javascript else output_as_html end if


Posting Permissions

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