0

I need validate textarea with this data:

string:data
string:data
string:google

I need allow only this format string in textarea. Allow break and one string with other with delimiter: ":".

I validate with:

$request->validate([
   'textarea' => 'required|string|regex:/:/'
]);

But this is not working. How I can fix it? I need rule for my situation.

Dumitru
  • 2,053
  • 6
  • 20
  • 45

1 Answers1

0

Try:

$request->validate([
   'textarea' => 'required|string|regex:/(.)+:(.)+/'
]);

Or if you need only "data" or "google" after the colon:

$request->validate([
   'textarea' => ['required','string','regex:/(.)+:(google|data)+/']
]);

PS note on the second you have to use an array if your regex has a pipe operator | (documentation)

Note: When using the regex / not_regex patterns, it may be necessary to specify rules in an array instead of using pipe delimiters, especially if the regular expression contains a pipe character.

lufc
  • 1,965
  • 2
  • 15
  • 19