3

My users enter some numbers in a textbox. The numbers format is 09XXXXXXXXX. The numbers are separated by Comma. like 09121234567,09351234568. I use the Regular Expression below to check the user input.

^(09\d{9},?)+

Everything is ok but the problem is that if I enter 0912123456709351234568 it still matches this regexp. I want the user to enter at least one number without comma but if the numbers are more than one then it should be separated by comma. What is the right regexp?

2 Answers 2

5

Try this pattern below,

^(09\d{9})(,09\d{9})*$

enter image description here

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

Comments

3

You can use this pattern:

^(09\d{9}(?:,|$))+$

So basically, the 09\d{9} can be followed by a comma or the end of the string, and the whole thing must be terminated by the end of the string.

This will capture the comma, however. If you'd like to omit it you can simply rearrange the groups:

^(?:(09\d{9})(?:,|$))+$

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.