0

I'm using old jQuery (1.4.2), and I cannot change this unfortunately. I must use this. But was testing and the new jQuery (3.1) made my problem, but I cannot use. So I have a problem:

I have a form input. I get this input value with jQuery:

var myInputValue = $( "#myInput").val();

For example this input's value: 22/22// , yes, double // and it's string of course.

And I have a regex pattern:

var pattern = new RegExp('[0-9A-Z]+(\/[0-9A-Z]+)*\/?', 'g');

And I use this pattern:

pattern.test(myInputValue);

console.log(pattern.test(myInputValue)); //its true, but I think its not true

And I made test. I didnt use variable for this, so directly:

console.log(pattern.test('22/22//')); //its false, and I think is false, so this is good.

So the new jQuery made my problem, but I cannot use. What do you think how to make I this task?

Thank you!

George
  • 6,630
  • 2
  • 29
  • 36
Árpád Jó
  • 11
  • 1
  • 5
  • Your jQuery version won't have anything whatsoever to do with your browser's regular expression engine. Also, "new jQuery made my problem" isn't at all clear. Can you edit your question to make it clear what you're asking? – T.J. Crowder Dec 19 '16 at 14:51
  • It is clear to me: 1) OP needs a whole string match, thus must enclose the pattern with `^` and `$`, 2) The `RegExp#test` should not be used with a regex with `/g` modifier, the `'g'` must be removed. And surely a regex literal notation would be cleaner: `var pattern = /^[0-9A-Z]+(?:/[0-9A-Z]+)*\/?$/;` – Wiktor Stribiżew Dec 19 '16 at 14:57
  • @WiktorStribiżew I tried, but it's not working. But I made this problem. I was using alternative solution. I make a function, that it made this string to good: $.each(houseNumberValue.match(/[0-9A-Z]+(\/[0-9A-Z]+)*\/?/g), function(key, value) { concatenate += value; }); return concatenate; – Árpád Jó Dec 20 '16 at 17:09

1 Answers1

-2

Because the substring 22/22/ matches your pattern the result is true. http://www.w3schools.com/jsref/jsref_regexp_test.asp

pattern.test belongs to JavaScript, not jQuery

Kevin Kendzia
  • 248
  • 1
  • 12