|
Posted by Christoph Burschka on 12/12/06 11:22
Bosconian schrieb:
> "Benjamin" <musiccomposition@gmail.com> wrote in message
> news:1165548753.790590.146590@n67g2000cwd.googlegroups.com...
>
>>Bosconian wrote:
>>
>>>I need a way to validate the followng data with these restrictions:
>>>
>>>no leading and trailing white space
>>>no trailing comma
>>>double quoted numeric/alpha pairs
>>>each pair on a separate line
>>>
>>>For example:
>>>
>>>"1","Peter"
>>>"2","Paul"
>>>"3","Mary"
>>>
>>>Any help is appreciated.
>>
>>A regular expression would be great here. Try this:
>>preg_match($data, "/^(\"\d+\",\"[A-Za-z]+\")+$/")
>>
>
>
> I tested your pattern, but it only recognizes the first line. I tried
> (unsuccessfully) inserting a carriage return (\r) after the last quote:
>
> preg_match($data, "/^(\"\d+\",\"[A-Za-z]+\"\r)+$/")
>
> Any suggestions on how to make it work for multiple lines?
>
>
>
I seem to remember preg_match() expects the pattern as the first, and
the string as the second argument. It appears to have worked for you the
other way around, however... is this interchangable?
Anyway, I'd split up the string and check each line separately:
$data_array=explode("\n",$data);
foreach ($data_array as $line) preg_match( [...] )
--
CB
[Back to original message]
|