0

in my laravel app I have following regex validation,

'modelname'    => 'required|regex:/^[A-Za-z0-9. -]+$/|unique:modols|max:255'

now I need ad ' symbol also to this modelname how can I do this?

Root
  • 35
  • 9

1 Answers1

0

You just need to add ' to your regex character class:

'modelname'    => 'required|regex:/^[A-Za-z0-9. \'-]+$/|unique:modols|max:255'
                                     Here ------^

Bear in mind that your regex have the - at the end of the character class, if not it will be treated as character class range, if so you will have to escape it with \-

Federico Piazza
  • 30,085
  • 15
  • 87
  • 123