JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old March 25th, 2008, 11:06 PM
Souliebaby Souliebaby is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 65 Souliebaby User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 1 h 5 m 28 sec
Reputation Power: 4
Red face Need Help Debugging Script/Error in Script - Check for "http", "www" and "[url" in comment field

Hi there

I've been trying to find a javascript code that will check for "http", "www" and "[url" in my comments field and then return "false" with an alert, but am having a lot of trouble finding one, let alone getting one to work.

Basically I have a contact form with a comments field, I removed all the crap I tried to get working to check for these problems as I had no luck whatsoever.

Code:
  if (theForm.comments.value == "")
  {
    alert("Please enter any relevant information in the comments field.");
    theForm.comments.focus();
    return (false);
  }


I am looking for something similar to the above, but to check for http, www and [url then to pop up an alert about not spamming the site..

Can anyone help me please?

Reply With Quote
  #2  
Old March 27th, 2008, 05:27 AM
Annie79 Annie79 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2007
Location: Beaverton OR
Posts: 17 Annie79 User rank is Just a Lowly Private (1 - 20 Reputation Level)  Folding Points: 49426 Folding Title: Beginner FolderFolding Points: 49426 Folding Title: Beginner FolderFolding Points: 49426 Folding Title: Beginner Folder
Time spent in forums: 7 h 25 m 11 sec
Reputation Power: 0
You can use the indexOf() to check if the character sequences exist in the string entered.

For specifically validating if a URL is present, you can also use any of the regex available for URL validation. Here's one I had from somewhere:
Code:
function isValidURL(url){ 
    var RegExp = /^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/; 
    if(RegExp.test(url)){ 
        return true; 
    }else{ 
        return false; 
    } 
} 

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJavaScript Development > Need Help Debugging Script/Error in Script - Check for "http", "www" and "[url" in comment field


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT