Reputation: 167
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..
Upvotes: 5
Views: 16366
Reputation: 1526
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)
Upvotes: 0
Reputation: 9291
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
Upvotes: 10