Title: Validation custom field
Last modified: December 14, 2024

---

# Validation custom field

 *  Resolved [smcweb1](https://wordpress.org/support/users/smcweb1/)
 * (@smcweb1)
 * [1 year, 5 months ago](https://wordpress.org/support/topic/validation-custom-field/)
 * I need help posting a validation code into my registration form. I was trying
   to follow the coding from this post from two years ago [https://wordpress.org/support/topic/add-custom-validation-for-a-field/](https://wordpress.org/support/topic/add-custom-validation-for-a-field/).
 * I have this code written, can anyone help me with getting the code right? I need
   to validate the field name “enrollmentnumber” so a user cant register using the
   same #.
 * Here is what i have:
 *     ```wp-block-code
       add_action( 'user_registration_validate_text','ur_validate_text_field',10,4);function ur_validate_text_field($single_form_field, $data, $filter_hook, $form_id) {    	global $wpdb;    $field_label = isset( $data->label ) ? $data->label : '';    $value = isset( $data->value ) ? $data->value : '';    if( 'enrollmentnumber' === $single_form_field->general_setting->field_name ) {		if(1 != empty($value)) {			$res = $wpdb->get_var("SELECT * from wp_users us join wp_usermeta um on um.user_id = us.ID 					where um.meta_key = 'user_registration_enrollmentnumber' and um.meta_value = $value");				if( count($res) > 0 ) {					add_filter( $filter_hook, function ( $msg ) use ( $field_label ) {						return __( $field_label . 'There is already a user with this number registered.', 'user-registration' );				   });				}  		 }    }if( 'enrollmentnumber' === $single_form_field->general_setting->field_name ) {		if(1 != empty($value)) { 			if( 1 != ctype_digit($value) ) {				add_filter( $filter_hook, function ( $msg ) use ( $field_label ) {					return __( $field_label . 'The number field can only contain numbers.', 'user-registration' );			   });			}		}	}}
       ```
   

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

 *  Plugin Support [sanjuacharya77](https://wordpress.org/support/users/sanjuacharya77/)
 * (@sanjuacharya77)
 * [1 year, 5 months ago](https://wordpress.org/support/topic/validation-custom-field/#post-18205358)
 * Hi [@smcweb1](https://wordpress.org/support/users/smcweb1/),
   Thanks for writing
   in and sorry for the delay. Once could you please proivde us the url of the form
   as well. We will check and get back to you.Regards!
 *  Plugin Support [sanjuacharya77](https://wordpress.org/support/users/sanjuacharya77/)
 * (@sanjuacharya77)
 * [1 year, 5 months ago](https://wordpress.org/support/topic/validation-custom-field/#post-18213058)
 * Hi [@smcweb1](https://wordpress.org/support/users/smcweb1/),
   Since we did not
   get a response from you, we are marking this topic as resolved. We believe the
   issues mentioned here are now resolved. Please create a new support thread if
   needed.
 * Thanks!

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

The topic ‘Validation custom field’ is closed to new replies.

 * ![](https://ps.w.org/user-registration/assets/icon-256x256.gif?rev=3284028)
 * [User Registration & Membership - Free & Paid Memberships, Subscriptions, Content Restriction, User Profile, Custom User Registration & Login Builder](https://wordpress.org/plugins/user-registration/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/user-registration/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/user-registration/)
 * [Active Topics](https://wordpress.org/support/plugin/user-registration/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/user-registration/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/user-registration/reviews/)

## Tags

 * [custom field](https://wordpress.org/support/topic-tag/custom-field/)
 * [validation](https://wordpress.org/support/topic-tag/validation/)

 * 2 replies
 * 2 participants
 * Last reply from: [sanjuacharya77](https://wordpress.org/support/users/sanjuacharya77/)
 * Last activity: [1 year, 5 months ago](https://wordpress.org/support/topic/validation-custom-field/#post-18213058)
 * Status: resolved