9

I've just started using laravel and I'm working on validating a textarea in one of my forms.

The textarea is for the users bio and so I only want to allow letters, numbers, spaces and the following characters: , . ? ; : ' " - () ! / @ $

This is what I have

$validator = Validator::make(Input::all(),
array('bio' => array('regex:[a-zA-Z0-9 ,\.\?;:\'"-\(\)!/@\$]')
    )
);

I've been searching and trying a lot to get it to work but I just can't figure it out.

Any help would be much appreciated.

Thanks

2
  • 1
    Don't know how it works in laravel, but you may need (a) delimiters (b) anchoring from start ^ to finish $, and (c) probably a + (1 character or more...). Commented Mar 15, 2014 at 22:36
  • 1
    Most of the things you are escaping don't need escaping inside of []. Also - specifies a range when it's inside of [] Commented Mar 16, 2014 at 2:26

1 Answer 1

18

Try this:

array('Regex:/^[A-Za-z0-9\-! ,\'\"\/@\.:\(\)]+$/')
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for the improvements ProgramFOX!
How can I put this regex in the laravel validation rule ^(\-?\d+(\.\d+)?),\s*(\-?\d+(\.\d+)?)$

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.