U
U
Username2018-09-12 13:37:36
JavaScript
Username, 2018-09-12 13:37:36

How to check the value of a regular expression that came from the server?

Good afternoon!
How to check the value of a regular expression that came from the server? As I understand it, you need to convert the string to a regular expression. I tried to check the expression through the test method, but I get the error Uncaught SyntaxError: Unexpected token ^ , I understand that I need to escape, but the regular expression does not work.
Pattern:"^\d{5}$"

var re = /^\d{5}$/;
if (re.test( "4" ) ) {
  alert("Данная строка соответсвует заявленому патерну");
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton fon Faust, 2018-09-12
@dalv_happy

new Regexp() to the rescue

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question