Form validate email address


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. // form element
  2. $form['email'] = array(
  3. '#type' => 'textfield',
  4. '#element_validate' => array('_valid_email'),
  5. '#required' => TRUE,
  6. '#default_value' => 'Enter your email address here',
  7. );
  8.  
  9. // validation function
  10. function _valid_email($element)
  11. {
  12. if ( !valid_email_address($element['#value']) ) {
  13. form_error($element, t('Please enter a valid email address'));
  14. }
  15. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.