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

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

@swordf1zh - welcome, and welcome to SO! :) Be sure to either accept answers, or let the answerer know what the issue is :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.