I am making a program that gets an input from the user, then makes a regular expression using that input.
Here is some example code:
<input id="a" type="text" />
<input type="button" value="Create" id="b" />
<script>
(function (z , code) {
var input = document.getElementById("a"),
b = document.getElementById("b");
function primary(){
var regEx = new RegExp("[A-Z]{3}[ ]\d{9}[ ]" + input.value.toUpperCase(), "g");
alert(regEx);
};
b.addEventListener("click",function(){
primary();
}, false);
}(this, document));
</script>
It works accept for this:
Say I use FooBar as my input. Instead of creating a regular expression that says, /[A-Z]{3}[ ]\d{9}[ ]FOOBAR/g I get a regular expression that says, /[A-Z]{3}[ ]d{9}[ ]FOOBAR/g. A d instead of \d.
Why is this not working properly? How can I correct this?
Thank you.
\\d, etc.