I posted the problem in the link above - regExpression.test .
Based on what I did as shown below, it also throws an error.
var regExpression=new RegExp("^([a-zA-Z0-9_\-\.]+)$"); alert (regExpression.test("11aa"));
You need to escape with \since you declare it as a string, for example:
\
var regExpression=new RegExp("^([a-zA-Z0-9_\\-\\.]+)$"); ^ ^ add these
You can test it here .
You can also use RegExp literal syntax/…/ :
/…/
var regExpression = /^([a-zA-Z0-9_\-\.]+)$/;
: . . , :
.
var regExpression = /^([a-zA-Z0-9_.-]+)$/;
Source: https://habr.com/ru/post/1768026/More articles:How can I match the next = / nextpage / value when I decorate the view with @login_required? - pythonC # / WPF: drag and drop images - c #VS2010 Add-In by adding a command to the context menu? - c #regExpression.test - javascriptCelery, Django .. creating a subtask / thread to launch a task / thread? - pythonRedirect error after logging in to Django 1.2 - django2D coordinate coordination - language-agnosticWhat is the scope of a java variable in a block? - javaconvert svg to html + css - htmlCSS-преобразование текста не отправляет верхний регистр в бизнес-уровень - htmlAll Articles