Title: Problem with custom validation
Last modified: November 11, 2020

---

# Problem with custom validation

 *  Resolved [Nicolas](https://wordpress.org/support/users/nchaccal/)
 * (@nchaccal)
 * [5 years, 7 months ago](https://wordpress.org/support/topic/problem-with-custom-validation/)
 * Hi, i want to do a custom validation to user_login field.
 * The thing is my custom validation works only in the registration form. But when
   try to edit profile of user already registered, i received an error message from
   WordPress. In the debug mode, wordpress told me something like this:
 * Undefined index: user_login in function.php
 * Uncaught error type: Argument 1 passed to CiValidator::validate_ci() must be 
   of the type string, null given, called in function.php
 * This is my code:
 *     ```
       /*validate user login*/
       add_action('um_submit_form_errors_hook_','um_custom_validate_username', 999, 1);
       function um_custom_validate_username( $args ) {
   
       class CiValidator
       {
           /**
            * @param string $ci
            * @return bool
            */
           public function validate_ci( string $ci ) : bool
           {
               $ci = $this->clean_ci($ci);
               $validationDigit = $ci[-1];
               $ci = preg_replace('/[0-9]$/', '', $ci );
   
               return $validationDigit == $this->validation_digit( $ci );
           }
   
           /**
            * @param string $ci
            * @return string
            */
           public function clean_ci( string $ci ) : string
           {
               return preg_replace( '/\D/', '', $ci );
           }
   
           /**
            * @param string $ci
            * @return int
            */
           public function validation_digit( string $ci ) : int
           {
               $ci = $this->clean_ci( $ci );
   
               $ci = str_pad( $ci, 7, '0', STR_PAD_LEFT );
               $a = 0;
   
               $baseNumber = "2987634";
               for ( $i = 0; $i < 7; $i++ ) {
                   $baseDigit = $baseNumber[ $i ];
                   $ciDigit = $ci[ $i ];
   
                   $a += ( intval($baseDigit ) * intval( $ciDigit ) ) % 10;
               }
   
               return $a % 10 == 0 ? 0 : 10 - $a % 10;
           }
       }
       	$validator = new CiValidator();
   
       	if ( isset( $args['user_login'] ) && !ctype_digit( $args['user_login'] ) || !$validator->validate_ci( $args['user_login'] ) ) {
       		UM()->form()->add_error( 'user_login', 'invalid document ID' );
       	}
       }
       ```
   
 * Any help will be appreciated. I dont have good skills in php :/
    -  This topic was modified 5 years, 7 months ago by [Nicolas](https://wordpress.org/support/users/nchaccal/).
    -  This topic was modified 5 years, 7 months ago by [Nicolas](https://wordpress.org/support/users/nchaccal/).
    -  This topic was modified 5 years, 7 months ago by [Nicolas](https://wordpress.org/support/users/nchaccal/).

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Thread Starter [Nicolas](https://wordpress.org/support/users/nchaccal/)
 * (@nchaccal)
 * [5 years, 7 months ago](https://wordpress.org/support/topic/problem-with-custom-validation/#post-13651866)
 * I already understood what was happening
 * In the login form, user_login field does not appear. Thats why says its null.
    -  This reply was modified 5 years, 7 months ago by [Nicolas](https://wordpress.org/support/users/nchaccal/).
 *  Plugin Contributor [Champ Camba](https://wordpress.org/support/users/champsupertramp/)
 * (@champsupertramp)
 * [5 years, 6 months ago](https://wordpress.org/support/topic/problem-with-custom-validation/#post-13667628)
 * Hi [@nchaccal](https://wordpress.org/support/users/nchaccal/)
 * Thanks for letting us know. I am closing this thread now.
 * Regards,

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Problem with custom validation’ is closed to new replies.

 * ![](https://ps.w.org/ultimate-member/assets/icon-256x256.png?rev=3160947)
 * [Ultimate Member – User Profile, Registration, Login, Member Directory, Content Restriction & Membership Plugin](https://wordpress.org/plugins/ultimate-member/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/ultimate-member/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/ultimate-member/)
 * [Active Topics](https://wordpress.org/support/plugin/ultimate-member/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/ultimate-member/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/ultimate-member/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [Champ Camba](https://wordpress.org/support/users/champsupertramp/)
 * Last activity: [5 years, 6 months ago](https://wordpress.org/support/topic/problem-with-custom-validation/#post-13667628)
 * Status: resolved