@@ -14,6 +14,16 @@ public function __construct(IRentableRepository $rentableRepo)
14
14
$ this ->rentableRepo = $ rentableRepo ;
15
15
}
16
16
17
+ /**
18
+ * Sanitize before rules()
19
+ */
20
+ protected function sanitizeInput ()
21
+ {
22
+ $ input = $ this ->all ();
23
+ $ input ['description ' ] = preg_replace ("~[\p{M}]~uis " , "" , $ this ->input ('description ' ));
24
+ $ this ->replace ($ input );
25
+ }
26
+
17
27
/**
18
28
* Get the validation rules that apply to the request.
19
29
*
@@ -25,12 +35,12 @@ public function rules()
25
35
26
36
return [
27
37
'rentable_id ' => 'required|integer|min:1|exists:App\Models\Rentable,id ' ,
28
- 'adress ' => 'required|string|min:3|max:150 ' ,
38
+ 'adress ' => 'required|string|min:3|max:150|regex:/^[a-zA-Z0-9_ .-]*$/ ' , // Regex for Adress
29
39
'postal_code ' => 'required|numeric|digits:4|min:1|max:9999 ' ,
30
40
'date_of_hire ' => 'required|date_format:Y-m-d|after_or_equal: ' . $ todayDate ,
31
41
'start_time ' => 'required ' ,
32
42
'end_time ' => 'required ' ,
33
- 'price ' => 'required|numeric|min:0.01|max:1000 ' ,
43
+ 'price ' => 'required|numeric|min:0.01|max:1000|regex:/^[0-9]+(\.[0-9]{1,2})?$/ ' , //Regex for Decimal with 2 decimal places
34
44
'bankaccount_nr ' => 'required|string|regex:/^[A-Z]{2}(?:[ ]?[0-9]){14,20}$/ ' , // Regex for IBAN numbers
35
45
'description ' => 'required|string|max:150 ' ,
36
46
];
@@ -43,6 +53,8 @@ public function rules()
43
53
*/
44
54
protected function getValidatorInstance ()
45
55
{
56
+ $ this ->sanitizeInput ();
57
+
46
58
return parent ::getValidatorInstance ()->after (function () {
47
59
// Get the current rentable
48
60
$ rentable = $ this ->rentableRepo ->getRentable ($ this ->input ('rentable_id ' ));
0 commit comments