I'm using the WordPress API to create an options page. One of the inputs need to have an email entered. I need to write a function that will validate the email entered and return it.
function nl_validate_settings( $input ) {
if ( $field_args = array( 'type' => 'email' ) ) {
foreach( $input as $email ) {
if ( ! preg_match( '/^[A-Za-z0-9!#$%&\'*+\/=?^_`{|}~-]+@[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)+[A-Za-z]$/', $email ) ) {
$email = "Invalid email address!";
}
}
return $email;
}
}
This isn't working and I don't know what I am doing wrong. It doesn't save emails when an email is entered correctly.
I've checked other answers on StackOverFlow but couldn't find anything that would fix the problem. Your help would be appreciated!
I don't know how to format it