0

I have a form, description, and I like to stop words like "www, http, //, @, .com, co.uk..."

I would like to stop all email and domains in this form but allow all types of characters spaces, comas, and latin characters with punctuation like "ç, ã, á, à..."

I have somethins like this

<code>
$().ready(function() {
// validate the description form when it is submitted
$("#descriptionform").validate();
});

$(document).ready(function(){
$.validator.addMethod("regex", function(value, element) {
return this.optional(element) || /^[a-z0-9 \_,.]+$/i.test(value);
}, "Description field can not include e-mail and/or urls.");
$("#regForm").validate();
});
</code>

Could you help me please? Thank you in advance

RAN
  • 59
  • 4
  • 1
    We cannot help you if you want to stop strings _like_ these. You need to be more specific. Can you provide an exhaustive list or a strict rule for what you want to exclude? – m0skit0 Nov 22 '12 at 12:06
  • So you want to prevent people from writing "www" or "http" into your form? Don't you think that's a not-so-great idea? What do you *really* want to prevent? And why don't you check validity on the server side? – Tomalak Nov 22 '12 at 12:21

1 Answers1

0

This is a regex that will match if the input doesn't contain the character sequences you want to stop:

^(?!.*www)(?!.*http)(?!.*//)(?!.*@)(?!.*\.com)(?!.*co\.uk).+
Bohemian
  • 412,405
  • 93
  • 575
  • 722
  • Already try to put like this but doesen't work "return this.optional(element) || /^(?!.*www)(?!.*http)(?!.*//)(?!.*@)(?!.*\.com)(?!.*co\.uk)+$/i.test(value);" – RAN Nov 22 '12 at 13:11
  • @RAN You are missing a dot before the plus `+`. See edited answer – Bohemian Nov 22 '12 at 16:10
  • Already try this "return this.optional(element) || /^(?!.*www)(?!.*http)(?!.*//)(?!.*@)(?!.*\.com)(?!.*co\.uk).+$/i.test(value);" with the dot before the plus + and doesen't work. But if I remove "(?!.*//)" he works ok. – RAN Nov 22 '12 at 19:52