Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel validation regex, breaks in view

So, I have the following rules in my model:

public static $rules = array(
    'name'            => 'required|alpha_dash|unique:subsidiaries',
    'internal_number' => 'required|alpha_dash|unique:subsidiaries',
    'expedition_rate' => array('required', 'regex:/^[0-9]{1,3}(\.?)[0-9]{1,2}$/'),
    'hundred_kg_rate' => array('regex:/^[0-9]{1,5}(\.?)[0-9]{1,2}$/'),
    'handling'        => array('regex:/^[0-9]{1,3}(\.?)[0-9]{1,2}$/'),
    'insurance'       => 'required|numeric',
);

But, for some reason, when the regex is applied in the pattern attribute tag in html... it breaks!

Result:

<input required="true" pattern="^[0-9]{" class="form-control" ....>
                               _________
                                 \
                                  => This right here should be
                               ^[0-9]{1,3}(\.?)[0-9]{1,2}$
like image 450
Alex Avatar asked Sep 23 '13 15:09

Alex


1 Answers

Try using like this.

array(
    'field' => 'regex:[a-z]'
);

Hope this would helpful.

like image 154
Vivek Pandey Avatar answered Sep 21 '22 21:09

Vivek Pandey