JavaScript Regular expression function is not working as expected [closed] - javascript

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
This regular expression is not working as expected.Please suggest other way to validate this regular expression in javascript.
var patt = new RegExp('^(PK\d{2}[A-Z]{4}\d{16})|(\d{9,20})$');
patt.test('PK12FKIE1234567890123456');

You need put both patterns inside a single group so that the anchors should apply to both.
var patt = /^(?:(PK\d{2}[A-Z]{4}\d{16})|(\d{9,20}))$/;

Related

How can i use javascript backticks? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
i am facing issue when using backticks , The browser show it string,
example:
<h2>${item.title}</h2>
Output:
${item.title}
I don't know where to using this. but simply you can use backticks like this.
In HTML
<div id="title"></div>
In Javascript
const titleTag = `<h2>${item.title}</h2>`;
const element = document.getElementById("title");
element.innerHTML = titleTag;

Ng pattern to accept pipe separated input in AngularJs [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I have a form and I want to accept pipe separated values for a particular field only in the format
4 digits|8digits|any number of digits.
I tried using ^\d{1,6}(|\d{1,6}){3}
But this is wrong.
Try \d{4}\|\d{8}\|\d* if the any number of digits can be 0, if not, then try \d{4}\|\d{8}\|\d+

Regex replace +46 to 0 JavaScript [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I'm trying to learn regex. I need to find +46 and replace it with 0. I've been racking my brain but I can't figure out the correct syntax. I'm trying to do it in JS with replace.
Any takers?
Use .replace():
"987654321+46".replace("+46", "0")

Replace "\r\n5" Using javascript [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I got a result "\r\n5".
I want to remove "\r\n" and take only number 5.
How do i take the number and remove "\r\n" using javascript replace function.
please anyone help me.
Why do you want to use replace us this
"\r\n5".match(/\d+/)[0]
The trim() method returns the string stripped of whitespace from both ends. trim does not affect the value of the string itself.,should be work
"\r\n5".trim();
JS FIDDLE

Add space after three numbers [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I'm trying to have my numbers in a format that is easier for the user to read.
Eg. Instead of: 12349568483, it would be: 12 349 568 483.
I was wondering if there is a simple way to do this?
var a = "12349568483";
a = a.split('').reverse().join('').replace(/([0-9]{3})/g, "$1 ").split('').reverse().join('');

Categories

Resources