5

I need to match regex and need to put condition based on result.. What I have tried is

var value1="4111111111111111"
    const str="^4[0-9]{12}(?:[0-9]{3})?$}"
var result=value1.match(str)
console.log(result)

Here I am getting value as null..

3
  • Can you please add the content inside value1 and the excepted result? Commented Dec 19, 2019 at 10:19
  • Please tell me more about you Regex. I try '5 2-5' as input value and match method work fine. Commented Dec 19, 2019 at 10:22
  • your pattern is somthing like that? 4111111111111(111) or 4111111111111111 Commented Dec 19, 2019 at 10:39

2 Answers 2

10

Try this :

var value1="4111111111111111"
var pattern = new RegExp('^4[0-9]{12}(?:[0-9]{3})?$}');
var result=pattern.test(value1);
console.log(result);

This will return either True or False

Sign up to request clarification or add additional context in comments.

Comments

0

If you pattern is somthimg like that: 4111111111111111 or 4111111111111111

then use this code:

const str="^4[0-9]{12}([0-9]{3})?$";

'4111111111111'.match(str)
'4111111111111111'.match(str)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.