SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Wizard nofel's Avatar
    Join Date
    Aug 2007
    Location
    Earth
    Posts
    1,766
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Question validating url confusion

    hi, i m working on a field that is of url. i am unable to use regex as i am new to JS, how can i use regex in my following condition
    Code JavaScript:
    var website = $('#website').val();
        if(website=='') {
            $("#website").after('<span class="error">Enter website.</span>');
            hasError = true;
            }
        else if(!urlReg.test(website)) {
                $("#website").after('<span class="error">Website should be in [url]http://www.website.com[/url] format.</span>');
                hasError = true;
            }
    for now. it go with any .com or if i enter .123 etc. help pls
    All those who wander aren't lost.

  2. #2
    Avid Logophile silver trophy
    ParkinT's Avatar
    Join Date
    May 2006
    Location
    Central Florida
    Posts
    2,342
    Mentioned
    192 Post(s)
    Tagged
    4 Thread(s)
    Code:
    urlReg = new RegExp(^http\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(/\S*)?$);
    Checks for the leading protocol, a good looking domain (two or three letter TLD; no invalid characters in domain) and a somwhat reasonable file path.

    HTH
    Don't be yourself. Be someone a little nicer. -Mignon McLaughlin, journalist and author (1913-1983)


    Git is for EVERYONE
    Literally, the best app for readers.
    Make Your P@ssw0rd Secure
    Leveraging SubDomains

  3. #3
    SitePoint Wizard nofel's Avatar
    Join Date
    Aug 2007
    Location
    Earth
    Posts
    1,766
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    can u help me in cooperate this in my condition. i donno how to start
    All those who wander aren't lost.


Bookmarks

Posting Permissions

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