2

in java I simply make:

boolean match = string.matches("\\d{2}-\\d{2}");

how do I make this in javascript?

2
  • 1
    var regex = new RegExp("\\d{2}-\\d{2}", ""); regex.test(string) Commented Sep 8, 2013 at 14:47
  • !!"22-34".match(/\d{2}-\d{2}/); Commented Sep 8, 2013 at 15:06

1 Answer 1

4

In javascript:

var inputString = '22-34';
var pattern = /\d{2}-\d{2}/;
var match = pattern.test(inputString); // match will equal true

MDN regular expression reference documentation

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

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.