Hi, I'm trying to check the format of the string with preg_match()
. It has to accept only the(zero or more of ,.* )(exactly 9 or 5 digit number)(1 or more of ,.* )(postive integer <= 4digits)(zero or more of ,.* )
format of strings.
Here, is what I tried:
((\s|\*|,|\.)*)(\d{4}|\d{10})((\s|\*|,|\.)+)(\d{1,4})((\s|\*|,|\.)*)
It is working with these numbers:
, *123456789, *51*,
=> true
(exactly 9), .*12345, *51*,
=> true
(exactly 5), .*123, *51*,
=> false
(less than 5)
This is where I failed:
, .*1234567891011, *51*,
=> true
(greater than 9), It is just considering the first 9 digits & ignoring others & returing true, but I should actually get false
, .*123456, *51*,
=> true
(in between 5 &9), same here, considering first 5 digits & returning true.
Thanks for any help!