0

How can I code a function in PHP to check input string with allowed pattern? my pattern is like this:

1-1341498217

First section is one digit integer from 0 to 9 and the second section after dash is 10 digits positive integer number.

Thanks.

1
  • I am a little bit confused. how can I make sure about provided solutions? I did some test but I think I've found malfunctioning. Commented Jul 14, 2012 at 19:57

3 Answers 3

2
preg_match("/\d-\d{10}/", $string);

?

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

Comments

1

use this preg_match("/^\d-[1-9]\d{9}$/", $string)

Comments

1
preg_match("/^\d-[1-9]{10}$/", $string)
                 //^--------------for positive digits

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.