Last active
February 19, 2016 12:26
Revisions
-
niraj-shah revised this gist
Feb 19, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ // validate that mobile number starts with '07' $rules = [ 'mobile' => 'required|numeric|startswith:07', ]; // custom validator called startswith -
niraj-shah created this gist
Feb 19, 2016 .There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ // validate that mobile number starts with '07' $rules = [ 'mobile' => 'required|numeric|startswith:07', ]; // custom validator called startswith Validator::extend('startswith', function( $attribute, $value, $parameters ) { return substr( $value, 0, strlen( $parameters[0] ) ) == $parameters[0]; }); // custom replacer, so we can replace :value in the message Validator::replacer('startswith', function( $message, $attribute, $rule, $parameters ) { return str_replace( [':value'], $parameters, $message ); }); // Error message for startswith failure $messages = [ 'startswith' => ':attribute needs to starts with :value' ]; // validate input $validation = Validator::make( Input::all(), $rules, $messages );