views:

45

answers:

1

I'm making a classifieds ads website where users submit ads through a form (like Craigslist). Many users write the title or description of their ads in UPPERCASE to get more attention, but I dont want to affect the overall appearance of the website.

I would like to stop this, but still allow the use of acronyms of less than three uppercase letters in a row (for example allow 'Located in the USA' but not 'LOOK, GREAT OFFER')

I'm a complete newbie with Validate and RegEx (just one weekend) so I need your help experts.

I'm using this method:

$.validator.addMethod("noCaps", function(value, element) {
   return this.optional(element) || /[A-Z]{4}/.test(value); 
}, "You are not permitted to input more than three uppercase letters in a row!");

But I'm getting the complete opposite result. How could I negate this RegEx to achieve the desired rule?

If somebody has a better idea of how to do it, is also welcome!

Thanks!!!

See/Edit Example Code

A: 

You can just add a negation (!) in front of it, like this:

$.validator.addMethod("noCaps", function(value, element) {
  return this.optional(element) || !/[A-Z]{4}/.test(value); 
}, "You are not permitted to input more than three uppercase letters in a row!");

You can give it a try here.

Nick Craver
nice!! thanks!!! =)
swordf1zh
@swordf1zh - welcome, and welcome to SO! :) Be sure to either accept answers, or let the answerer know what the issue is :)
Nick Craver
thanks, its just what I needed!... Im loving SO..
swordf1zh