Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
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..
value1
method
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
True
False
Add a comment
If you pattern is somthimg like that: 4111111111111111 or 4111111111111111
4111111111111111
then use this code:
const str="^4[0-9]{12}([0-9]{3})?$"; '4111111111111'.match(str) '4111111111111111'.match(str)
Required, but never shown
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.
Explore related questions
See similar questions with these tags.
value1and the excepted result?methodwork fine.