I am attempting to create a input directive in Angular which can be configured from a remote endpoint.
The object below should result in a input-field with type=text and should only be set to valid if the input is a 6-digit number.
{
inputfield: {
"name": "6-digit code",
"type": "text",
"pattern": "/^\d{6}$/"
}
}
The problem I am encountering is that if I use $setValidity and check the value with a Regex generated from pattern I get the following:
var pattern = new RegExp("^\d{6}$");
console.log(pattern.toString());
=> "/^d{6}$/"
Which is fine, as \ is escaped as expected. I do have access to the endpoint delivering the data. This endpoint is a REST-endpoint written in Java. So at the endpoint the Regex is defined as follows:
String regex = "/^\\d{6}$/";
So, to sum up:
From endpoint: "/^\\d{6}$/"
Received at client: "/^\d{6}$/"
Constructing RegExp from the received object gives: "/^d{6}$/"
Wanted RegExp: /^\d{6}$/
Can this be achieved without declaring the Regex at the endpoint with quadrouple slashes (i.e. "/^\\\\d{6}$/")?