File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -43,6 +43,17 @@ protected function validateFormatoCpfCnpj($attribute, $value)
4343 {
4444 return $ this ->validateFormatoCpf ($ attribute , $ value ) || $ this ->validateFormatoCnpj ($ attribute , $ value );
4545 }
46+
47+ /**
48+ * Valida o formato do PIS/PASEP/NIS/NIT
49+ * @param string $attribute
50+ * @param string $value
51+ * @return boolean
52+ */
53+ protected function validateFormatoNis ($ attribute , $ value )
54+ {
55+ return preg_match ('/^\d{3}\.\d{5}\.\d{2}-\d{1}$/ ' , $ value ) > 0 ;
56+ }
4657
4758 /**
4859 * Valida CPF
@@ -224,5 +235,27 @@ protected function validateTituloEleitor($attribute, $value)
224235
225236 return true ;
226237 }
238+
239+ /**
240+ * Valida PIS/PASEP/NIS/NIT
241+ * @param string $attribute
242+ * @param string $value
243+ * @return boolean
244+ */
245+
246+ protected function validateNis ($ attribute , $ value )
247+ {
248+ $ nis = sprintf ('%011s ' , preg_replace ('{\D} ' , '' , $ value ));
249+
250+ if (strlen ($ nis ) != 11 || preg_match ("/^ {$ nis [0 ]}{11}$/ " , $ nis )) {
251+ return false ;
252+ }
253+
254+ for ($ d = 0 , $ p = 2 , $ c = 9 ; $ c >= 0 ; $ c --, ($ p < 9 ) ? $ p ++ : $ p = 2 ) {
255+ $ d += $ nis [$ c ] * $ p ;
256+ }
257+
258+ return ($ nis [10 ] == (((10 * $ d ) % 11 ) % 10 ));
259+ }
227260
228261}
You can’t perform that action at this time.
0 commit comments