Validate user required fields I'm using Drupal 7 and I have some PHP pages that depends on my Drupal site.
In the PHP page, I tried to add a user programmatically in order the check the exception:

try {
  $new_user = array(
    'name' =&gt; 'user'
  );
  user_save('', $new_user);
} catch (Exception $e) {
  echo $e-&gt;getMessage();
}


I didn't give all the required field, like email and some custom fields that I set in Home » Administration » Configuration » People » Account settings, but Drupal still added this user.

I need the following:


Get all user field(s) and check if they are required or not 
Get error on exception when I'm trying to add user without required fields


How should I do that?
I think you shouldn't create user this way, as it's bypassing all the controls made by drupal.

You can retrieve registration form this way:

drupal_get_form('user_register_form');


And print it like this:

print(drupal_render(drupal_get_form('user_register_form')));