SitePoint Sponsor

User Tag List

Results 1 to 16 of 16
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2007
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    JS regex simple url

    I need a regex that will validate with these examples

    kenaesthetic.com
    www.kenaesthetic.com

    I pulled this but doesn't allow the . in .com or www.

    /^[1-9]\d{2,4}\.\d{2}$/

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by EZPA55 View Post
    I need a regex that will validate with these examples
    With some examples from that web site?

    Could you please be more specific about the examples strings of text that you need to validate.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2007
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I need

    a url to validate that does not have the http://

    just plain www.anyurl.com or just anyurl.com

    very simple just not sure how to write regexs

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    The regex library is likely to be your best friend then.

    For example, have a look at the first regular expression at the matches for url where it shows you some example successful matches, and non-successful matches.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  5. #5
    SitePoint Enthusiast
    Join Date
    Nov 2007
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Successful matches
    www.kenaesthetic.com
    kenaesthetic.com

    non-successful matches
    http://www.kenaesthetic.com

    I've look at that site and those examples seem to give me syntax error in DW

  6. #6
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by EZPA55 View Post
    I've look at that site and those examples seem to give me syntax error in DW
    You can test your regular expression over at the Regular Expression Tester page.
    Which do you think is more likely to be wrong? A regular expression from a site that specialises in regular expressions, or a program like dreamweaver?

    Dreamweaver is doing it wrong. It commonly does that.
    Show us what you're doing with Dreamweaver and we'll try to help you through your problem.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  7. #7
    SitePoint Enthusiast
    Join Date
    Nov 2007
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried the one from that site but it gives me a syntax error like every other one i've gotten from there.

    It also ruins the script

  8. #8
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by EZPA55 View Post
    I tried the one from that site but it gives me a syntax error like every other one i've gotten from there.

    It also ruins the script
    You may also find similar problems with many other regular expressions, because they all work in the same way.

    Show us what you're doing, and we'll find out what's going wrong.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  9. #9
    SitePoint Enthusiast
    Join Date
    Nov 2007
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    simple validation script matching a reg ex

    Code:
    $('#CAT_Custom_194495').blur(function(){
    	  var $input = $(this); // define the input object with jQuery
    	  if(this.value.match(/^[A-Z\s]+$/i))
    		$('#weburl').removeClass('error'),
    		$('#weburl').addClass('green'); // an example of removing the class error from the input field
    	  else
    		$('#weburl').removeClass('green'),
    		$('#weburl').addClass('error'); // adding the error class if invalid content is entered
    	});

  10. #10
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by EZPA55 View Post
    simple validation script matching a reg ex

    Code:
    $('#CAT_Custom_194495').blur(function(){
    	  var $input = $(this); // define the input object with jQuery
    	  if(this.value.match(/^[A-Z\s]+$/i))
    		$('#weburl').removeClass('error'),
    		$('#weburl').addClass('green'); // an example of removing the class error from the input field
    	  else
    		$('#weburl').removeClass('green'),
    		$('#weburl').addClass('error'); // adding the error class if invalid content is entered
    	});
    That code is saying that when you leave the '#CAT_Custom_194495' field, that its value should be checked, and a different field called '#weburl' should be coloured depending on the validity of the '#CAT_Custom_194495' field. I'm not sure if that's what you intend the code to do or not.

    What is the HTML form code that the script is being used with?

    Also, why is $input there? It doesn't appear to be used by anything.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  11. #11
    SitePoint Addict AllanP's Avatar
    Join Date
    Sep 2010
    Location
    Australia
    Posts
    286
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If your url is http://www.anyurl..... you might drop the http://, but what about urls like http://anyurl ...... ? Do you want to drop the http:// in this case?

  12. #12
    SitePoint Addict AllanP's Avatar
    Join Date
    Sep 2010
    Location
    Australia
    Posts
    286
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Looking back I see that you are prepared to accept anyurl.com or similar.

  13. #13
    SitePoint Enthusiast
    Join Date
    Nov 2007
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That worked. Thanks. I almost gave up having to explain the simplicity of this. I really need to learn how to write regexs.

    Thanks so much

  14. #14
    SitePoint Enthusiast
    Join Date
    Nov 2007
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is it only .com or .edu what if there is another ending like .net? I think I'd like it to end with either three or two letter to catch all endings:
    Is this right as an ending?

    .\d{3 | 2}$/

  15. #15
    SitePoint Enthusiast
    Join Date
    Nov 2007
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can you write it up so it will accept 2 letters as well. It looks like it will but it doesn't

  16. #16
    SitePoint Enthusiast
    Join Date
    Nov 2007
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am using the second one that should work with both 2 or 3 letters at the end but it is not accepting the two letter.

    example: kenaesthetic.me

    check the form http://kenaesthetic.com/rfp.htm


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
  •