2

Any one can help converting this php regex pattern to js compatible one?

$delimiter = "-";
$phone = "some number from the client";
var_dump(
    preg_match($phone,"|^([0-9]{1,3}".$delimiter."[0-9]{1,4}".$delimiter."[0-9]{4,12}(#[0-9]{1,4})?)$|")
);

Thanks

2
  • Can you give an example of what you would like to keep and reject? Commented May 30, 2011 at 11:11
  • (1-2numbers)-(1-2numbers)-(7-9numbers + avoid start with 0 + avoid repeats 1111111 + avoid 1234567) without the brace. this is a phone number verification Commented May 30, 2011 at 11:14

1 Answer 1

1
var delimiter = "-",
    phone = "8-989-895",
    re = new RegExp("^[0-9]{1,3}"+delimiter+"[0-9]{1,4}"+delimiter+"[0-9]{4,12}(?:[0-9]{1,4})?$");
console.log(re.test(phone));
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.