working with regular expressions and jquery

I have this example fiddle:
https://jsfiddle.net/h6vkt3jg/2/

In this example I'm using this regex pattern:

/<\/|\/>/

With this pattern only when you type </ together or /> together does validation pass and the button becomes enabled.

When you run it, it looks like this. The button is disabled.
 
Run1.PNG
So if you type the symbols separately that doesn’t pass.

Run2ErrorMessage.PNG


If I type the </ symbols together regardless whether there is text before or after it, validation passes.
 
Run3Pass1.PNG
If I type the /> symbols together regardless whether there is text before or after it, validation passes.


Run3Pass2.PNG

How do I revised my regex example to do the opposite?
I want to add Not to this regex pattern /<\/|\/>/

So in my example the validation should pass for everything except </ or this />

The tooltip should only popup if I type </ or this />
LVL 1
maqskywalkerAsked:
Who is Participating?
 
gr8gonzoConsultantCommented:
To look for strings that do NOT have </ or />, use this regex:
/^((?!<\/|\/>).)*$/.test(value)

Or what David S. said.
0
 
David S.Commented:
To reverse it, simply add the not operator ("!") immediately before the expression (the JS one, not necessarily the RegEx one, but in this case it's the same, since you're using one of the methods of RegEx objects).

            jQuery.validator.addMethod("HTMLCheck1", function (value, element) {
                return this.optional(element) || !/<\/|\/>/.test(value);
            }, "Only LTForwardSlash or ForwardSlashGT is allowed");

Open in new window

0
 
Rgonzo1971Commented:
Hi,

pls try
^(<\/.*\/>|(?!.*<\.*)(?!.*\/>.*).*)$

Open in new window

REgards
0
 
maqskywalkerAuthor Commented:
thanks. great examples.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.