|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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? ![]() |
|
#2
|
|||
|
|||
|
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;
}
}
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > JavaScript Development > Need Help Debugging Script/Error in Script - Check for "http", "www" and "[url" in comment field |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|